PHP PDO:SQLSTATE [HY093]:参数号无效:混合命名和位置参数

时间:2017-01-12 23:10:15

标签: php mysql pdo

我收到错误:

  

SQLSTATE [HY093]:参数号无效:混合名称和位置参数

当我尝试运行以下代码时:

     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不太满意,但是有很多问题,但我自己无法解决这个问题。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

使用正确的参数化查询。并且UPDATE语句中的分配必须以,分隔,而不是AND

$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
));