[support] Place holders in SQL query
Warren Vail
warren at vailtech.net
Mon Apr 11 01:06:18 UTC 2011
This syntax is a hold over from the old C programming language and I
have seen several of the newer Drupal books recommending it, not sure if
there is a preference in D7. but essentially what nan wich (intrigued
by the name) says is correct, if you build your query string it (as
should all strings) begin with a single or double quote and end with the
same. I personally can't see any problem coding multiple %s and %d
placeholders in one string then coding them as a list of variables, but
don't forget that your string and list need to be passed to a function
(fscanf comes to mind), but I believe the new drupal get db functions
(sorry I don't remember their names) do this.
Warren Vail
On 4/10/2011 5:55 PM, Austin Einter wrote:
> 1.
> When we do a SQL query, if we want to pass value to query, we make use
> %d for integers or %s for strings.
> Similarly do we have any place holders for arrays.
> 2.
> I am facing a below typical problem, can somebody tell me what should
> I do?
> Below query works fine.
> SELECT skillid FROM {resubmt_skills} WHERE resubmt_skills.skillname
> IN (*'PHP', 'HTML', 'SQL'*)
> But in above query search string *'PHP', 'HTML', 'SQL' *is hard coded.
> I want to make the query generic.
> Lets say in custom search form, user entered search string PHP,
> Telecom, HTML,, so how can I write a generic query.
> Thanks
> Austin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110410/0adc46a5/attachment.html
More information about the support
mailing list