Figuring out db_query()
Yeah, I use it all the time. But there's a few things about Drupal's db_query (and the database-specific MySQL etc. functions behind it, and Drupal functions like db_fetch_object() that I'd like to have very clear in my head:
- If the query is successful but results in an empty set, is
$resultstill a numeric reference or just zero?
Parameters
$query A string containing an SQL query.
... A variable number of arguments which are substituted into the query using printf() syntax. Instead of a variable number of query arguments, you may also pass a single array containing the query arguments.
Return valueA database query result resource, or FALSE if the query was not executed correctly.
Just a side note, but that "..." for "A variable number of arguments" really drives home the case Larry Garfield has made against that setup. The function can't even define itself!
See also setting errors in Drupal (Agaric's guide in progress) for reporting SQL errors.
See also agaric's page on db_last_insert_id().
Yeah, I use it all the time. But there's a few things about Drupal's db_query (and the database-specific MySQL etc. functions behind it, and Drupal functions like db_fetch_object() that I'd like to have very clear in my head:
- If the query is successful but results in an empty set, is
$resultstill a numeric reference or just zero?
Parameters
$query A string containing an SQL query.
... A variable number of arguments which are substituted into the query using printf() syntax. Instead of a variable number of query arguments, you may also pass a single array containing the query arguments.
Return valueA database query result resource, or FALSE if the query was not executed correctly.
Just a side note, but that "..." for "A variable number of arguments" really drives home the case Larry Garfield has made against that setup. The function can't even define itself!
See also setting errors in Drupal (Agaric's guide in progress) for reporting SQL errors.
See also agaric's page on db_last_insert_id().
More like this
- Drupal won't set values to NULL with db_query %d system
- Floating point number with Drupal's db_query
- Figuring out User-based Node Access in Drupal (again), some notes
- Figuring out Organic Groups Project module integration: output of project module's link altering hook
- Decimal numbers and Drupal's db_query (sprintf)


Comments
Post new comment