我想使用with更新SQL
表。但是我不断收到以下错误PHP
PDO
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\core\functions\update_projects.php on line 31
我只是无法理解我要去哪里错了。
$j = 1;
$chunk_count = count($update)/7;
$backwards = array_reverse($update);
$chunks = array_chunk($backwards, 7);
var_dump($chunks[1]);
try {
for($i = 0; $i < $chunk_count; $i++ ) {
$update_project = $db->prepare('
UPDATE projects
SET comments = ?,
contact = ?,
est_end = ?,
est_start = ?,
apm = ?,
pm = ?
WHERE id = ?
');
foreach ($chunks[$i] as $field => $val) {
$update_project->bindValue($j++, $val, PDO::PARAM_STR);
}
$update_project->execute();
}
echo 'Projects Updated';
} catch(PDOException $e) {
die($e->getMessage());
}
如果我var_dump($chunks[1])
看到以下值
array(7) { [0]=> string(13) "some comments" [1]=> string(7) "jim doe" [2]=> string(6) "1-1-14" [3]=> string(7) "12-1-13" [4]=> string(8) "jane doe" [5]=> string(7) "jon doe" [6]=> string(2) "16" }
那么我的代码中的问题在哪里?任何帮助表示赞赏