[support] Place holders in SQL query
Warren Vail
warren at vailtech.net
Mon Apr 11 16:10:53 UTC 2011
I'm beginning to see that the root of his problem was that one of his
parameters was an array and there is no place holder for inserting an array
(might be a nice enhancement, don't you think? "%as" or "%s[]" for an array
of strings, carried in the array of parameters as a nested array. The other
alternative was to recognize this and do the implode to turn the nested
array into a string external to db_placeholders.
Warren Vail
_____
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of nan wich
Sent: Monday, April 11, 2011 5:31 AM
To: support at drupal.org
Subject: Re: [support] Place holders in SQL query
This is exacty what db_placeholders() is for. It takes an array and build
the correct number of %s fields (or %d depending on the type parameter) for
inserting into your IN clause.
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King,
Jr.
_____
From: Austin Einter <austin.einter at gmail.com>
To: support at drupal.org
Sent: Sun, April 10, 2011 8:55:16 PM
Subject: [support] Place holders in SQL query
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/20110411/829e5b7c/attachment-0001.html
More information about the support
mailing list