PDO mysql查询语句问题

时间:2017-03-21 18:44:52

标签: php mysql pdo

我尝试了请求

DB::query('INSERT INTO users VALUES (\'\', :nom, :prenom, :pseudo, :birthdate, :level, :classroom, :contactNumber1, :contactNumber2,:pathphoto, :schoolName, :password, :email, :town, :registerDate)',
  array(':nom'=>'',
  ':prenom'=>'', 
  ':pseudo'=>$username,
  ':birthdate'=>'',
  ':level'=>'',
  ':classroom'=>'',
  ':contactNumber1'=>'',
  ':contactNumber2'=>'',
  ':pathphoto'=>'',
  ':schoolName'=>'',
  ':password'=>$password,
  ':email'=>$email,
  ':town'=>'',
  ':registerDate'=>'')
);

但是我收到了错误

Fatal error: Uncaught exception 'PDOException'

带有消息

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in C:\wamp64\www\mongbaki\social\classes\DB.php

我想知道问题出在哪里。

1 个答案:

答案 0 :(得分:-1)

排除故障后,我发现了错误。

DB::query('INSERT INTO users (nom, prenom, pseudo, birthdate, level, classroom, contactNumber1, contactNumber2, pathphoto, schoolName, password, email, town, registerDate) VALUES (:nom, :prenom, :pseudo, NOW(), :level, :classroom, :contactNumber1, :contactNumber2, :pathphoto, :schoolName, :password, :email, :town,  NOW())', array(':nom'=>"",':prenom'=>"", ':pseudo'=>$username,':level'=>"",':classroom'=>"",':contactNumber1'=>"",':contactNumber2'=>"",':pathphoto'=>"",':schoolName'=>"",':password'=>$password,':email'=>$email,':town'=>"" ));