在我所有的查询中使用bind_param
,我现在想要使用IN(?)
,其中列表中元素的数量可能会有所不同。mySQL bind_param与IN(?)
$sql_db->prepare
,
->bind_param
,
->execute()
,
->store_result()
,
->bind_result
// the code below does not work as the query only matches on element 'a':
$locations = ('a','b','c','d','e');
SQLout ("SELECT Name FROM Users WHERE Locations IN (?)",
array('s', $locations), array(&$usrName));
// the code below does work as a brute-force method,
// but is not a viable solution as I can't anticipate the number of elements in $locations going forward:
SQLout ("SELECT Name FROM Users WHERE Locations IN (?,?,?,?,?)",
array('sssss', $locations[0],$locations[1],$locations[2],$locations[3],$locations[4]), array(&$usrName));
有没有人想出了一个更优雅的解决这个
的SQLOUT功能?
[PHP PDO的可能重复稍微接近工作代码:我可以将数组绑定到IN()条件吗?](http://stackoverflow.com/questions/920353/php-pdo-can-i-bind-an-array-to-an-in-condition) – 2013-02-19 15:07:37
PDO的答案与mysqli问题无关。在处理可变数量的准备语句方面,PDO与mysqli相比是一个天堂 – 2013-02-19 15:22:04