Home > Net >  unquoted string in shell_exec
unquoted string in shell_exec

Time:09-28

I am try to run a query with like operator for shell command but every time it gives error of unquoted string

 $abc = shell_exec("mysql  --user=**** --password=**** --host=**** db -e
 
'SELECT TABLE_NAME,
       COLUMN_NAME 
 FROM information_schema.COLUMNS
 WHERE   COLUMN_NAME LIKE '\"'%lead%'\" 
 AND TABLE_NAME  LIKE '\"'%leads%'\"  "); '

it runs for single conditions seperaetly like

WHERE   COLUMN_NAME LIKE '\"'%lead%'\"

or

WHERE TABLE_NAME  LIKE '\"'%leads%'\" 

but with AND operator combined it gives unquoted string err . i tried by removeing and adding quotes , but not working please suggest

CodePudding user response:

if you want quotes to be part of the string, you need to escape it with backslash \"

CodePudding user response:

Just escape your quotes with backslash.

$abc = shell_exec("mysql --user=**** --password=**** --host=**** db -e 'SELECT TABLE_NAME,COLUMN_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME LIKE '\"'%lead%'\" AND TABLE_NAME LIKE '\"'%leads%'\"'");

CodePudding user response:

Use this

shell_exec("mysql --user=**** --password=**** --host=**** db -e 'SELECT TABLE_NAME,COLUMN_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME LIKE '\"'%lead%'\" AND TABLE_NAME LIKE '\"'%leads%'\"'");
  • Related