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
  • 16,827
  • 6
  • 33
  • 48
Kalpit tandon
  • 119
  • 1
  • 3
  • 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,602
  • 2
  • 26
  • 64