$ emptyNumbers有2个项目,$ qMarks是“?,?”。有什么问题?
if(($key = array_search($row['nummer'], $emptyNumbers)) !== false) {
unset($emptyNumbers[$key]);
}
echo sizeof($emptyNumbers)."==>".$qMarks; // 2 ==> ?,?
$qMarks = str_repeat('?,', count($emptyNumbers)-1) . '?';
$getPlayerData=$db->prepare( "SELECT number,surname,firstname,position,job FROM player WHERE nummer IN ($qMarks)");
$getPlayerData->execute($emptyNumbers);
--> Error: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
答案 0 :(得分:1)
问题是我之前从$ emptyNumbers中取消了值,并且我没有对数组重新排序,因此存在空值。
if(($key = array_search($row['nummer'], $emptyNumbers)) !== false) {
unset($emptyNumbers[$key]);
//delete the gaps in the array!
$emptyNumbers = array_values($emptyNumbers);
}
$qMarks = str_repeat('?,', count($emptyNumbers)-1) . '?';
$getPlayerData=$db->prepare( "SELECT number,surname,firstname,position,job FROM player WHERE nummer IN ($qMarks)");
$getPlayerData->execute($emptyNumbers);