【发布时间】:2014-08-11 03:40:51
【问题描述】:
我正在尝试使用 BIT 类型值更新表中的数据,如下所示:
// $show_contact is either '1' or '0'
$query->bindValue(':scontact', $show_contact, PDO::PARAM_INT);
问题是,它永远不会改变值,它仍然是在 PHPMyAdmin 上设置的“1”。我尝试了不同的 PDO::PARAM_ 类型但没有成功,其他一切正常。
编辑完整脚本
$sql = "UPDATE users SET password = :password, address = :address, postal = :postal, city = :city, contact = :contact, show_contact = :scontact WHERE id = :id";
$query = $dbh->prepare($sql);
$query->bindValue(':id', $user->id, PDO::PARAM_INT);
$query->bindValue(':password', md5($password), PDO::PARAM_STR);
$query->bindValue(':address', $address, PDO::PARAM_STR);
$query->bindValue(':postal', $postal, PDO::PARAM_STR);
$query->bindValue(':city', $city, PDO::PARAM_STR);
$query->bindValue(':contact', $contact, PDO::PARAM_STR);
$query->bindValue(':scontact', $show_contact, PDO::PARAM_INT);
$query->execute();
【问题讨论】:
-
也许你把它作为字符串发送
'1' -
顺便说一句。你应该使用 sha-256 而不是 md5 security.stackexchange.com/questions/19906/…
-
@RiggsFolly 谢谢,
PDO::ATTR_EMULATE_PREPARES完成了这项工作