My SQL statement has the
IN
The conditions, in my imagination can write code like this
$ids = Array (2344, 5523, 9332), $st = $pdo->prepare (' SELECT * FROM table_name WHERE ID (: ID) '); $st->bindparam (' id ') , $ids); $st->execute ();
But this implementation PDO will error, unable to bind an array variable, there is no good solution
Reply content:
I have a condition in my SQL statement that IN
can be written like this in my imagination
$ids = Array (2344, 5523, 9332), $st = $pdo->prepare (' SELECT * FROM table_name WHERE ID (: ID) '); $st->bindparam (' id ') , $ids); $st->execute ();
But this implementation PDO will error, unable to bind an array variable, there is no good solution
PDO does not support binding arrays.
Or you don't have to use bindings.
$ids = Array (2344, 5523, 9332);//filter ids slightly $in = implode (', ', $ids); $st = $pdo->prepare (' SELECT * ' from table_name WHERE ID in ('. $in. ') '); $st->execute ();
If you stick with the bindings, maybe that's it.
$ids = Array (2344, 5523, 9332);//automatic construction of multiple $st = $pdo->prepare (' SELECT * FROM table_name WHERE ID in (?,?,?) '); foreach ($ids as $k = $id) $st->bindvalue (($k + 1), $id); $st->execute ();
I just said this in the morning. PDO does not support this binding, see:
http://segmentfault.com/q/10100000001 ... Third article.
08 wrote Lotusphp's documentation specifically annotated, PDO does not support this, Upstairs Zhao Yi is also lotusphp developers
PDO does not support this binding, but it can be done by a third-party class, which is a PDO class that I do, which makes it easy to use where in.
Https://github.com/lincanbin/PHP-PDO-MySQL-Class
The use of the method is also very simple, first a new object
And then
query("SELECT * FROM fruit WHERE name IN (?)",array('apple','banana'));?>
, other SQL syntax can be used to see the Https://github.com/lincanbin/PHP-PDO-MySQL-Class