PHP PDO:SQLSTATE[HY093]:无效参数编号:混合命名参数和位置参数
我得到一个错误: SQLSTATE[HY093]:无效参数编号:混合命名参数和位置参数 当我尝试运行以下代码时:PHP PDO:SQLSTATE[HY093]:无效参数编号:混合命名参数和位置参数,php,mysql,pdo,Php,Mysql,Pdo,我得到一个错误: SQLSTATE[HY093]:无效参数编号:混合命名参数和位置参数 当我尝试运行以下代码时: public function getScore($matchID,$setone,$settwo,$getChallengerScore,$getOpponentScore,$fileOpponentData,$fileChallengerData) { try { $stmt = $this->db->prepare("UPDATE
public function getScore($matchID,$setone,$settwo,$getChallengerScore,$getOpponentScore,$fileOpponentData,$fileChallengerData)
{
try
{
$stmt = $this->db->prepare("UPDATE matches SET `winner` = $setone
AND `looser` = $settwo
AND `winner_score` = $getChallengerScore
AND `looser_score` = $getOpponentScore
AND `opponent_blob` = '".$fileOpponentData."'
AND `challenger_blob` = '".$fileChallengerData."'
WHERE `id` = $matchID");
#var_dump($stmt);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
我对PDO不太在行,没有太多问题,但我自己无法解决。
任何帮助都将不胜感激。使用正确的参数化查询。而
UPDATE
语句中的赋值必须用、
分隔,而不是用和
分隔
$stmt = $this->db->prepare("UPDATE matches SET `winner` = :setone
, `looser` = :settwo
, `winner_score` = :getChallengerScore
, `looser_score` = :getOpponentScore
, `opponent_blob` = :fileOpponentData
, `challenger_blob` = :fileChallengerData
WHERE `id` = :matchID");
$stmt->execute(array(
':setone' => $setone,
':settwo' => $settwo,
':getChallengerScore' => $getChallengerScore,
':getOpponentScore' => $getOpponentScore,
':fileOpponentData' => $fileOpponentData,
':fileChallengerData' => $fileChallengerData,
':matchID' => $matchID
));
不要替换变量,使用参数化查询。我还想知道为什么有时在同一个字符串中使用变量插值,而有时使用串联。因此,这里不代替简单的手动更新语法。手册提示:
和
???所有不同的赋值应该用,
,而不是和
@riggsfully分隔。我想知道为什么这个错误会导致错误消息。它应该只将所有和作为指定表达式的一部分。致获胜者
。谢谢你,这就是确切的解决方案。