MySQL 查询将字段设置为 0 而不是空白字符串
这个让我很困惑我有一个 MySQL 查询,正在通过 PDO 运行:
$stmt = $db->prepare( "UPDATE member SET acode='' AND status='active' WHERE username=:u" );
$stmt->bindValue( ':u', $member->username, PDO::PARAM_STR );
$stmt->execute();
由于某种原因,acode
字段设置为 0。它是
`acode` varchar(8) NOT NULL
用使用准备好的语句时我需要做一些特别的事情吗?
This one's puzzling me. I have a MySQL query, being run though PDO:
$stmt = $db->prepare( "UPDATE member SET acode='' AND status='active' WHERE username=:u" );
$stmt->bindValue( ':u', $member->username, PDO::PARAM_STR );
$stmt->execute();
The acode
field gets set to 0 for some reason. It was created with
`acode` varchar(8) NOT NULL
Is there something special I need to do when using prepared statements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
天哪,
问题出在查询的这一部分:
AND 将其转换为 '' AND status='active' 的布尔检查,其计算结果为 0。将查询更改为:
Gidday,
The problem comes with this part of your query:
the AND turns this into the boolean check of '' AND status='active', which evaluates to 0. Change your query to: