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.

Files: 
CommentFileSizeAuthor
#9 1441852-return_value-9.patch661 byteschris.leversuch
PASSED: [[SimpleTest]]: [MySQL] 190 pass(es).
[ View ]
#5 1441852-return_value-5.patch924 byteschris.leversuch
PASSED: [[SimpleTest]]: [MySQL] 190 pass(es).
[ View ]
#3 1441852-return_value.patch627 byteschris.leversuch
PASSED: [[SimpleTest]]: [MySQL] 190 pass(es).
[ View ]

Comments

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

Issue tags:+Novice

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

Status:Active» Needs review
StatusFileSize
new627 bytes
PASSED: [[SimpleTest]]: [MySQL] 190 pass(es).
[ View ]

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

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.

Status:Needs work» Needs review
StatusFileSize
new924 bytes
PASSED: [[SimpleTest]]: [MySQL] 190 pass(es).
[ View ]

Is this better?

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

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" ?

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

Status:Needs work» Needs review
StatusFileSize
new661 bytes
PASSED: [[SimpleTest]]: [MySQL] 190 pass(es).
[ View ]

Attached.

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

That looks good to me, thanks!

Status:Reviewed & tested by the community» Fixed

Thanks, committed, pushed.

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