SQL LIKE不能使用PHP,但可以在phpmyadmin中工作

I would like to use a LIKE form of query in SQL to auto-implement a text field with this php function :

function getNumOFAutoImplement($chaine){
   $o_CAD = new connect();

   $sql = 'SELECT * FROM tb_numero_affaire WHERE numero_OF LIKE \':numof%\'';

   $param = array(":numof"=>$chaine);
   $result = $o_CAD->read($sql, $param);
   return $result;
}

The function is working well went I use this request in my function :

$sql = 'SELECT * FROM tb_numero_affaire WHERE numero_OF LIKE :numof';

It's also working when I directly past the following line in the phpMyAdmin SQL box :

SELECT * FROM tb_numero_affaire WHERE numero_OF LIKE '%456%';

$sql ="SELECT * FROM tb_numero_affaire WHERE numero_OF LIKE '%".$chaine."%'";

Bind it with the wildcards, like;

function getNumOFAutoImplement($chaine){
   $o_CAD = new connect();

   $sql = 'SELECT * FROM tb_numero_affaire WHERE numero_OF LIKE :numof';

   $param = array(":numof"=>$chaine.'%');
   $result = $o_CAD->read($sql, $param);
   return $result;
}
  • Don't need to quote the placeholders as it will treat it as the literal string ':numof%'.