SQLSTATE[HY093]:参数数量无效:绑定(bind)变量数量与标记数量不匹配
我知道有几个问题存在同样的问题。但我检查了所有答案,问题仍然无法解决。真的希望有人能帮助我。非常感谢!
session_start();
$cid = $_POST['cid'];
$pContent = $_POST['pContent'];
$sContent = $_POST['sContent'];
$insert = "INSERT INTO 'Card'('cardID', 'creator', 'primaryLanguage',
'secondaryLanguage', 'primaryContent', 'secondaryContent')
VALUES (:cid, 'abc', 'English', 'Chinese', ':pContent', ':sContent')";
try {
$stmt = $dbh->prepare($insert, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$stmt->bindValue(":cid", $cid, PDO::PARAM_INT);
$stmt->bindValue(":pContent", $pContent, PDO::PARAM_STR);
$stmt->bindValue(":sContent", $sContent, PDO::PARAM_STR);
$stmt->execute();
unset($stmt);
} catch (Exception $e) {
echo 'Exception : ' . $e->getMessage() . "\n";
die();
}
最佳答案
查询中很少有错误。
列名称不需要单引号
占位符的绑定(bind)值不需要单引号
所以查询应该是这样的
INSERT INTO
Card(
cardID,
creator,
primaryLanguage,
secondaryLanguage,
primaryContent,
secondaryContent
)
VALUES
(
:cid,
'abc',
'English',
'Chinese',
:pContent,
:sContent
);
关于php - SQLSTATE[HY093] : Invalid parameter number (parameters not match),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29449087/