0

I have a table name as test. In test table there is column test1. test1 column has string value "abc & def" and i have create a string variable $str = "abc & def". When i'll try to execute like query (select * from test where test1 like '%$str%'). this will give nothing in result. can any one help?

Progman
  • 14,690
  • 4
  • 32
  • 46
Kalpit tandon
  • 119
  • 2
  • 10

1 Answers1

0

Am assuming you are using core (vanilla) PHP:

Something like below :

$esc_str = $db->quote($str);
// this is for PDO; for MySQLi use $db->escape_string($str) instead
$qry = "select * from test where test1 like '%$esc_str%'"

use the below :

$esc_str = $db->quote($str);
$qry = "select * from test where test1 like '%".$esc_str."%'"

or

$esc_str = $db->quote($str);
`select * from test where test1 like "%$esc_str%"`

this example converts php variable to https://www.virendrachandak.com/techtalk/php-double-quotes-vs-single-quotes/

Hope it helps :)

Damian Yerrick
  • 4,464
  • 2
  • 21
  • 60