在PHP中,如何判断pg_query()是否为返回数据的查询? [英] In PHP, how to tell if pg_query() was a query that returns data?

查看:294
本文介绍了在PHP中,如何判断pg_query()是否为返回数据的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,成功的 mysqli_query()如果没有数据,则返回true;如果存在数据,则返回 mysqli_result 对象是数据(即查询是 SELECT SHOW DESCRIBE EXPLAIN )。

So a successful mysqli_query() returns true if there is no data and it returns a mysqli_result object if there is data(ie the query was a SELECT, SHOW, DESCRIBE or EXPLAIN).

但成功使用 pg_query()总是返回相同的内容(查询结果资源),无论是否返回任何数据。

But with a successful pg_query() it always returns the samething(a query result resource) regardless of whether or not there's any data coming back.

我可以使用 pg_query()返回值,以确定查询是否为 SELECT SHOW DESCRIBE EXPLAIN 就像我可以使用 mysqli_query()

Can I use the pg_query() return value to determine if the query was either SELECT, SHOW, DESCRIBE or EXPLAIN like I can do with mysqli_query()?

推荐答案

没有完全证明的方法可以从pg扩展功能确定选择还是插入/更新。可以使用两个函数,但是仅当某些行返回或受sql影响时才起作用。

there is no full proof way to determine 'select' vs 'insert / update' from pg extension functions. two function can be used but work only if some rows are returned or affected by the sql.

// update / insert / delete sql and affect some row 
pg_num_rows($res); // 0
pg_affected_rows($res); // n

// select return some result
pg_num_rows($res); // n
pg_affected_rows($res); // 0

这篇关于在PHP中,如何判断pg_query()是否为返回数据的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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