[support] Place holders in SQL query

Austin Einter austin.einter at gmail.com
Mon Apr 11 10:35:23 UTC 2011


Thanks Warren, Pierre
I got it working with place hoolders.
Best Regards
Austin


On Mon, Apr 11, 2011 at 10:35 AM, Warren Vail <warren at vailtech.net> wrote:

> Not sure what you mean by generic, and never used the db_placeholders
> function, but this should work;
>
> $skillnames = array("PHP", "HTML","SQL");
> $tblname = "resubmt_skills";
> $query = sprintf("SELECT skillid FROM %s WHERE skillname in ('%s')",
> $tblname, "'".implode("', '",$skillnames)."'");
> //execute and fetch query results here
>
> not real elegant, but nothing is as elegant as the solution that works
> and maintainers can understand.
>
> Warren Vail
>
> On 4/10/2011 6:33 PM, Greg Knaddison wrote:
> > On Sun, Apr 10, 2011 at 6:55 PM, Austin Einter<austin.einter at gmail.com>
>  wrote:
> >> 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.
> >>
> > There's a handy function you need called db_placeholders -
> >
> >
> http://api.drupal.org/api/drupal/includes--database.inc/function/db_placeholders/6
> >
> > There are some examples on that page, but if you want more help be
> > sure to provide more of your example code.
> >
> > Cheers,
> > Greg
> >
> >
>
> --
>  [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110411/bd823441/attachment-0001.html 


More information about the support mailing list