[英]how to query multiple select using IN with pdo
how would you do this using pdo 您将如何使用pdo做到这一点
$post = Array
(
[0] => 558
[1] => 494
[2] => 469
[3] => 459
[4] => 452
[5] => 451
)
$ids = implode(',' post);
mysql_query('Select * where post IN ('$ids'));
currently i'm doing 目前我在做
$query = "Select * where post in (:ids);";
$stmt = $pdo=>prepare($query);
$stmt =>execute(array('ids'=> $ids);
but this does not seem too work 但这似乎不太可行
Your code seem to be invalid.Try like this : 您的代码似乎无效。尝试这样:
$array=array("558","494","469","459","452","451");
$in_list = "'".implode("','",$array)."'";
$stmt = $this->db->prepare('Select * FROM table where post IN ('.$in_list.')');
$stmt->execute();
For detail about prepare statement you can read here . 有关prepare语句的详细信息,您可以在这里阅读。
You can dynamically build your placeholders ?
您可以动态构建占位符?
$post = Array(....);
//count $post size, repeat a string of '?,'
$in = str_repeat('?,', count($post) - 1) . '?';
$query = "SELECT * FROM tbl WHERE post IN ($in);";
$stmt = $pdo=>prepare($query);
$stmt =>execute($post);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.