In PHP, how to tell if pg_query() was a query that

2019-07-15 11:58发布

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).

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.

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()?

1条回答
三岁会撩人
2楼-- · 2019-07-15 12:18

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
查看更多
登录 后发表回答