我正在尝试使用带有数组形式参数的简单 MySQL 插入查询。它一直告诉我参数的数量是错误的。我尝试了以下方法,都产生了相同的错误:
$stmt3 = $link->prepare('INSERT INTO messages VALUES(null, :room, :name, :message, :time, :color)');
$stmt3->execute(array(':room' => $Clean['room'],':name' => $Clean['name'],':message' => $Clean['message'],':time' => $time,':color:' => $Clean['color']));
和
$stmt3 = $link->prepare('INSERT INTO messages VALUES(:null, :room, :name, :message, :time, :color)');
$stmt3->execute(array(':null' => null, ':room' => $Clean['room'],':name' => $Clean['name'],':message' => $Clean['message'],':time' => $time,':color:' => $Clean['color']));
以及专门声明列以避免空插入:
$stmt3 = $link->prepare('INSERT INTO messages (room, name, message, time, color) VALUES(:room, :name, :message, :time, :color)');
$stmt3->execute(array(':room' => $Clean['room'],':name' => $Clean['name'],':message' => $Clean['message'],':time' => $time,':color:' => $Clean['color']));
这是我第一次使用 PDO(我通常使用 mysqli,但我当前的共享主机没有 mysqlnd 插件,这使我无法使用 prepare(),所以从这个角度来看任何见解都是值得赞赏的。