php - Binding issues of slash with quotes -


i using php mysql-pdo , symfony

issue : have query stated below

  status in (:status) 

with value of status a','b.

and when bind sting escaping below

  status in ('a\',\'b') 

and hence wrong output.

pleass help

prepared statement can represent complete data literal only. not part of literal, nor complex expression, nor identifier. either string or number only. thus, query doesn't work binding complex expression, not because of quotes

one have create query placeholders representing every array member, , bind array values execution:

$ids = array(1,2,3); $stm = $pdo->prepare("select * t id in (?,?,?)"); $stm->execute($ids); 

to make query more flexible, it's better create string ?s dynamically:

$ids = array(1,2,3); $in  = str_repeat('?,', count($arr) - 1) . '?'; $sql = "select * table column in ($in)"; $stm = $db->prepare($sql); $stm->execute($ids); $data = $stm->fetchall(); 

of course, if have other variables bound, need add them values array:

$ids = array(1,2,3); $in  = str_repeat('?,', count($arr) - 1) . '?'; $sql = "select * table column in ($in) , category=?"; $stm = $db->prepare($sql); $ids[] = $category; //adding member array $stm->execute($ids); $data = $stm->fetchall(); 

the code become quite bloated that's pdo can offer handle such complex cases. further improvement 1 can invent own placeholders support such complex data types.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -