Agaric Design Collective

Figuring out db_query()

 
By Benjamin Melançon
on 18 Aug
0 comments

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 $result still 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 value

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

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.