Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只在 mysql 用户上设置了 SELECT 权限
然后,当我运行UPDATE ...查询
UPDATE ...
$sth = $db->prepare( $update_sql ); if (!$sth) { echo "fail"; } else { echo "Ok"; }
打印Ok,但在表中没有更新。
Ok
问题:为什么打印Ok而不是打印fail?
fail
您可能需要execute您准备的查询:
execute
$sth->execute();
准备好的语句本身不对数据库做任何事情。该文档提供了更多细节。
请记住,exceute调用是您可以绑定SQL 占位符值的时间。
exceute
...因为您没有执行该语句 - 您只是准备了它。
function try_to_run($sql, $db) { $sth = $db->prepare( $update_sql ); if (false===$sth) return false; $r=$sth->execute(); return $r; } if (false===try_to_run($sql, $db)) { echo "fail"; } else { echo "Ok"; }