我可以使用以下代碼在PDO準備語句內成功實現IN子句。MYSQL - 具有多個IN子句的PDO
in_array = array(1,2,3);
$in = str_repeat('?,', count($in_array) - 1) . '?';
$sql = "SELECT * FROM my_table WHERE my_value IN ($in)";
$stm = $db->prepare($sql);
$stm->execute($in_array);
$data = $stm->fetchAll();
我該怎麼做多個$ in?例如,我已經失敗嘗試了以下內容:
in_array1 = array(1,2,3);
$in1 = str_repeat('?,', count($in_array) - 1) . '?';
in_array2 = array(4,5,1);
$in2 = str_repeat('?,', count($in_array) - 1) . '?';
$sql = "SELECT * FROM my_table WHERE (my_value1 IN ($in1)) AND (my_value2 IN ($in2))";
$stm = $db->prepare($sql);
$stm->execute($in_array1,$in_array2);
$data = $stm->fetchAll();
我認爲它必須做與STM->執行,但不能肯定,幫助表示讚賞
'執行()'需要** ** 1的參數,這是參數... – Rizier123