[development] Programmatically creating SQL queries

Andy Fowlston andy at pedalo.co.uk
Fri Mar 11 13:33:13 UTC 2011

Hi all,

Is there a preferred way in Drupal to programmatically create SQL queries? Currently I'm building a query to pull some webform data from selected component fields. I see a few choices:

1. Build the query with db_query() placeholders, build an argument array, and make the call using call_user_func_array().

2. Use sprintf() to build up a complete string, and pass that directly to db_query().

3. Use other functions to sanitise the arguments.

Is there any preferred method? Guessing number 2...


. . . . . . . 
Andy Fowlston
+44 (0)20 8747 5068
andy at pedalo.co.uk
Skype: andy.pedalo

This email is intended only for the above named addressee/s. This email may be confidential or legally privileged. If you have received this email and you are not a named addressee, you must not use, copy, distribute or disclose the email or any part of its contents or take any action in reliance on it. If you have received this email in error, please email the sender by replying to this message and delete it from your system. All reasonable precautions have been taken to ensure no viruses are present in this email. 

pedalo limited cannot accept responsibility for loss or damage arising from the use of this email or attachments and recommends that you subject these to your virus checking procedures prior to use. Any views or opinions presented are solely those of the author and not necessarily those of Pedalo Limited

Please consider the environment before printing this email

More information about the development mailing list