mysqli_stmt :: result_metadata在插入,更新,删除查询时是否返回false? [英] Does mysqli_stmt::result_metadata return false on insert, update, delete queries?

查看:99
本文介绍了mysqli_stmt :: result_metadata在插入,更新,删除查询时是否返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点不了解-关于更新,插入,删除查询result_metadata返回false吗?因为:

$meta = $stmt->result_metadata();
if($meta === false){
    throw new Exception(...));
}

当我尝试运行更新,插入或删除查询时引发异常.但是,仅在出错时才应为假. (来自php手册)

解决方案

该函数旨在返回有关您刚刚查询过的数据(元数据!)的数据.通常,插入行,更新行和删除行的操作实际上不会返回结果集.

(至少在MySQL中不这样.在某些其他数据库中,例如Postgres,有RETURNING子句...)

摘自mysqli_stmt_result_metadata手册页上的评论:

如果result_metadata()返回false,但是error/errno/sqlstate告诉您未发生错误,则意味着您的查询是不产生结果集的查询,即INSERT/UPDATE/DELETE查询而不是SELECT查询. /p>

这在文档中进行了说明,其中说:如果传递给mysqli_prepare()的语句是产生结果集的语句,则mysqli_stmt_result_metadata()返回结果对象",但是可能每个人都不清楚这到底意味着什么

I'm a bit not understanding - on update, insert, delete queries result_metadata returns false? Because:

$meta = $stmt->result_metadata();
if($meta === false){
    throw new Exception(...));
}

throws the exception when i try to run update, insert or delete query. But it should be false only on error. (from php manual)

解决方案

The function is intended to return data about the data you've just made a query about (metadata!). The action of inserting rows, updating rows, and deleting rows usually doesn't actually return a result set.

(At least not in MySQL. In certain other databases, like Postgres, there's the RETURNING clause...)

From the comments on the mysqli_stmt_result_metadata manual page:

If result_metadata() returns false but error/errno/sqlstate tells you no error occurred, this means your query is one that does not produce a result set, i.e. an INSERT/UPDATE/DELETE query instead of a SELECT query.

This is stated in the documentation where it says "If a statement passed to mysqli_prepare() is one that produces a result set, mysqli_stmt_result_metadata() returns the result object", but it might not be clear to everyone what this entails exactly.

这篇关于mysqli_stmt :: result_metadata在插入,更新,删除查询时是否返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆