[support] db_select()->condition()

Earnie Boyd earnie at users.sourceforge.net
Wed Jul 11 18:35:42 UTC 2012


This is an old thread (May 24th) and answered to satisfaction some
time ago.  David, you responded then also.

On Wed, Jul 11, 2012 at 12:05 PM, Metzler, David <metzlerd at evergreen.edu> wrote:
> I seem to be missing some of the messages on this thread, so I apologize
> if this question has already been answered more thoroughly.
>
> You appear to be confusing db_query syntax with db_select. The query
> builder does not take tokens.  This might help grok db_select.
>
> db_select('mytable', 'mt')
>   ->fields('mt', array('mycolumn'))
>   ->condition('mycolumn', '%' . $mystring . '%', 'LIKE')
>   ->execute();
>
> Like is particularly confusing because it basically takes a regular
> expression inside the quotes.
>
> Hope this helps... Dave
>
>
>
> On 7/11/2012 6:30 AM, John Summerfield wrote:
>> Earnie Boyd wrote:
>> > I have an existing module I'm trying to convert to DBTNG and have a
>> > condition I need a suggestion on.
>> >
>> > Original statement is something like
>> > SELECT mt.myvar FROM {mytable} mt WHERE mystring LIKE '%%%s%%';
>> >
>> > I want to change it to
>> > db_select('mytable', 'mt')
>> >   ->fields('mt', array('myvar'))
>> >   ->condtion('mystring', '%:mystring%', LIKE)
>> >   ->execute();
>> >
>> > The problem is condition() only takes three parameters, what would
> you
>> > suggest to use to replace :mystring?  I'm using t() but that seems
>> > like a misuse of it.
>> >
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
> --
> [ Drupal support list | http://lists.drupal.org/ ]



-- 
Earnie
-- https://sites.google.com/site/earnieboyd


More information about the support mailing list