【问题标题】:pdo execute Invalid parameter number: parameter was not definedpdo 执行无效的参数号:未定义参数
【发布时间】:2012-10-24 16:46:48
【问题描述】:

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

我总是收到此错误: “10-24 17:59:08.829: D/test(1794): Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter” number: 参数是未定义

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

【问题讨论】:

  • 您的参数数组中缺少 ':isTournament'
  • AND user_id = :$user_id';应该是 AND user_id = :user_id';
  • 哇,快!谢谢你,我完全忽略了它。
  • 对不起,这段代码很丑。 :)

标签: php sql pdo


【解决方案1】:

查询中有 14 个参数,但执行数组中只有 13 个。看起来好像数组中缺少 isTournament 参数。

【讨论】:

    猜你喜欢
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 2022-01-10
    相关资源
    最近更新 更多