delete mysql 返回,成功的MySQL DELETE返回什么?如何检查DELETE是否成功?

Using PHP, I am trying to delete a record, but I want to check if it was successful or not. Is anything returned from a successful DELETE FROM foo where bar = 'stuff'?

Alternatively, do you know any other ways to check if a DELETE was successful? Or am I better off just making sure the row exists before I delete it? I am trying to avoid another query if possible.

解决方案

Assuming you are using mysql_query:

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

If you are using PDO::exec, then the manual says this:

PDO::exec() returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, PDO::exec() returns 0.

Don't want to answer snipe, but since this was selected as the answer, I should note that mysql_query will return TRUE even if the query did not actually remove anything. You should use mysql_affected_rows to check for that.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值