使用PDO时遇到一些问题。这一切似乎都是正确的,但我收到了这个错误
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ':permissao' for column 'permissao' at row 1\n
这是打印输出的代码
$this->nome = $nome;
$this->email = $email;
$salt = $this->generateSalt();
$permissao = 10;
$activo = 0;
#encripta chama a funcao para encriptar a password do utilizador
$this->password = $this->pwdEncript($password, $salt);
$params = array('nome'=>$this->nome,
'email'=> $this->email,
'password'=> $this->password,
'salt'=>$salt,
'permissao'=>$permissao,
'activo'=>$activo);
$sql = "INSERT INTO sys_users(nome,email,password,salt,permissao,activo)
VALUES(':nome',':email',':password',':salt',':permissao',':activo')";
try
{
$sth = $this->db->prepare($sql);
$sth->execute($params);
}
catch(PDOException $e)
{
echo 'Erro ao inserir na base de dados'.$e->getMessage().'\n';
}
Permissao是mysql表上的INT。
很高兴为此提供任何帮助;)
答案 0 :(得分:3)
在评论中已经说过,但看起来你不需要占位符周围的引号。只需依靠Prepared Statement机制为您完成。
注意:对于MySQL,PDO默认模拟预准备语句。为了提高安全性,您可能希望将其设置为使用真实的预处理语句。
$pdo -> setAttribute (PDO::ATTR_EMULATE_PREPARES, false);
答案 1 :(得分:2)
试试这个:
$sql = "INSERT INTO sys_users(nome,email,password,salt,permissao,activo)
VALUES(:nome,:email,:password,:salt,:permissao,:activo)";