API page: http://api.drupal.org/api/drupal/includes%21database.mysql-common.inc/fu...

The return values listed on the page do not include TRUE, whilst (at least using mysqli) a successful INSERT query will make db_query() return a boolean TRUE.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mdupont’s picture

This is what PHP official documentation says:

  • mysqli: "For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE."
  • mysql: "For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. "
  • pg_query (PostgreSQL): returns "A query result resource on success or FALSE on failure. "
jhodgdon’s picture

Issue tags: +Novice

Sounds like something that needs to be updated in the documentation - thanks!

chris.leversuch’s picture

Status: Active » Needs review
FileSize
627 bytes

Something like this?
I assume this doesn't need fixing in D8 or D7 since the database system changed a lot.

jhodgdon’s picture

Status: Needs review » Needs work

I don't think "resultset" is a word, even though the official PHP documentation apparently uses it? Also, maybe we should give examples of which queries return result sets, like the PHP docs in #2 do?

And yes, this is drupal 6 only.

chris.leversuch’s picture

Status: Needs work » Needs review
FileSize
924 bytes

Is this better?

jhodgdon’s picture

Status: Needs review » Needs work

That looks better! I am wondering if we can combine the mysql and mysqli parts?

Also, our style guidelines in the Drupal project require a , before the final or in a list:
apples, oranges, or bananas

chris.leversuch’s picture

The PHP docs area slightly different for mysql/mysqli - mysql has "and other statements returning resultset" after the list of query types. I guess it could be that they're actually the same and the PHP docs are misleading.

Should I remove the distinction between the 2 and just say "Successful SELECT, SHOW, DESCRIBE, EXPLAIN, or other queries which return a set of results will return a database query result resource" ?

jhodgdon’s picture

That seems like a good idea to me (combining as you suggest).

chris.leversuch’s picture

Status: Needs work » Needs review
FileSize
661 bytes

Attached.

jhodgdon’s picture

Title: Missing return value » Return value docs on db_query() are lacking important information
Status: Needs review » Reviewed & tested by the community

That looks good to me, thanks!

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed, pushed.

Automatically closed -- issue fixed for 2 weeks with no activity.