2017-01-12 33 views
-2

私はエラーを取得する:私は次のコードを実行しようとするとPHP PDO:SQLSTATE [HY093]:無効なパラメータ番号:混合という名前と位置パラメータ

SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters

 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にはあまり関係がありませんが、多くの問題はありませんでしたが、これは私自身では解決できません。 ご協力いただければ幸いです。

+0

変数を代入しないで、パラメータ化されたクエリを使用します。 – Barmar

+0

また、同じ文字列内で可変補間を使うことがあり、他の時に連結を使うことがあるのも不思議です。 – Barmar

+0

___SOは、ここで簡単なマニュアルを置き換えることはできません.___ UPDATEの構文を見てください。そのマニュアルのhttp://dev.mysql.com/doc/refman/5.7/en/update.html _HINT:_ 'AND' ???? – RiggsFolly

答えて

0

適切にパラメータ化されたクエリを使用します。また、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 
)); 
+0

ありがとう、これは正確な解決策でした。 – Xamber

関連する問題