Sử dụng bind_param
trên tất cả các truy vấn của tôi, bây giờ tôi muốn sử dụng một số IN(?)
trong đó số phần tử trong danh sách có thể thay đổi.mySQL bind_param với IN (?)
Các SQLout chức năng Tôi đang sử dụng ở đây về cơ bản không một $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));
Có ai tìm ra một giải pháp thanh lịch nhiều đến thế này?
thể trùng lặp của [PHP PDO : Tôi có thể liên kết một mảng với điều kiện IN() không?] (Http://stackoverflow.com/questions/920353/php-pdo-can-i-bind-an-array-to-an-in-condition) –
PDO câu trả lời không có gì để làm với các vấn đề mysqli. PDO là thiên đường so với mysqli về xử lý số biến số của các câu lệnh đã chuẩn bị –