pdo execute参数号无效:未定义参数

时间:2012-10-24 16:46:49

标签: php sql pdo

我正在尝试使用pdo进行简单的UPDATE查询,但在查看问题5小时后我就丢失了它。也许你们中的一些人知道我做错了什么。

我总是收到这个错误: “10-24 17:59:08.829:D / test(1794):警告:PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:无效参数”number:parameter was未定义

$name = $_POST['name'];
$buyin = $_POST['buyin'];
$result = $_POST['result'];
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$location = $_POST['location'];
$isTournament = $_POST['isTournament'];
$participants = $_POST['participants'];
$endPosition = $_POST['endposition'];
$comment = $_POST['comment'];
$blinds = $_POST['blinds'];
$pause = $_POST['pause'];

$game_id = $_POST['game_id'];
$user_id = $_POST['user_id'];


try {
    $dbconn = 'mysql:host=' . DBHOST . ';dbname=' . DBDATA;
    $db = new PDO($dbconn, DBUSER, DBPASS);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

$sql = 'UPDATE game SET name = :name AND buyin = :buyin AND result = :result AND startDate = :startDate AND endDate = :endDate AND
location = :location AND isTournament = :isTournament AND participants = :participants AND endposition = :endposition AND comment = :comment AND blinds = :blinds AND pause = :pause
WHERE game_id = :game_id AND user_id = :$user_id';
$statement = $db->prepare($sql);

$boolean = $statement->execute(array(':name' => $name, ':buyin' => $buyin, ':result' => $result,':startDate' => $startDate, ':endDate'
=>$endDate, ':location'=> $location, ':participants'=> $participants, ':endposition' => $endPosition, ':comment' => $comment, ':blinds' => $blinds, ':pause' => $pause, ':game_id' => $game_id,':user_id' => $user_id));

我的mysql表看起来像这样:

Naam    Type    
 1  game_id int(11)         
 2  user_id int(11)         
 3  name    varchar(45) 
 4  buyin   double          
 5  result  double          
 6  startDate   bigint(20)      
 7  endDate bigint(20)          
 8  location    
 9  isTournament    
 10 participants    
 11 endposition 
 12 comment text    
 13 blinds  text    
 14 pause   bigint(20)

1 个答案:

答案 0 :(得分:6)

查询中有14个参数,但执行数组中只有13个参数。似乎数组中缺少isTournament参数。