$statement = $connection->prepare("INSERT INTO test(emailAddress, password) VALUES(:emailAddress, :password)");
$data = array("emailAddress" => "test1", "password" => "test", "abc" => 123);
if($statement->execute($data)) {
echo $connection->lastInsertId();
} else {
echo "error";
}
我知道令牌的数量超过了所需的数量,但有时候我的阵列可以有更多,我需要它们。
Invalid parameter number: number of bound variables does not match number of tokens'
PDO可以忽略额外的参数吗?
答案 0 :(得分:2)
不,PDO要求您具有与准备好的查询中的参数数量相同的值。
$keys = array("emailAddress", "password");
$data = array("emailAddress" => "test1", "password" => "test", "abc" => 123);
if($statement->execute(array_intersect_key($data, array_flip($keys)))) {
. . .