PHP PDO 准备&执行 MySQL UPDATE 语句不起作用 - 难住了!
我正在为我的应用程序开发一个超级简单的计数器。我可以使用“$date”和“$c”插入行,但更新不起作用。
这有效:
$c = 8;
$today = date('Y-m-d');
$insert_count = $db->prepare("INSERT INTO COUNTER (COUNTER.date, clicks) VALUES ('" . $today . "', ?)");
$insert_count->execute(array($c));
这不
$c = 8;
$today = date('Y-m-d');
$update_count = $db->prepare("UPDATE COUNTER SET clicks = clicks + ? WHERE COUNTER.date = '" . $today . "'");
$update_count->execute(array($c));
没有错误,什么也没有。
I'm working on a super-simple counter for my application. I am able to insert rows using '$date' and '$c' just fine, but updating does not work.
This works:
$c = 8;
$today = date('Y-m-d');
$insert_count = $db->prepare("INSERT INTO COUNTER (COUNTER.date, clicks) VALUES ('" . $today . "', ?)");
$insert_count->execute(array($c));
This does not
$c = 8;
$today = date('Y-m-d');
$update_count = $db->prepare("UPDATE COUNTER SET clicks = clicks + ? WHERE COUNTER.date = '" . $today . "'");
$update_count->execute(array($c));
No errors, nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为?绑定占位符可用于计算。您是否尝试过使用命名绑定参数?
当你说没有错误时,这个命令执行后没有输出?
I don't think the ? binding placeholder works with calculations. Have you tried using named binding parameters instead?
When you say there are no errors, there is no output for this command after execute?