使用bind_param
我所有的查询,我现在想使用IN(?)
列表中元素数量可以变化的地方。
我在这里使用的 SQLout 函数基本上做了一个$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));
有没有人想出一个更优雅的解决方案?