[support] db_select()->condition()
Earnie Boyd
earnie at users.sourceforge.net
Fri May 25 12:04:46 UTC 2012
On Thu, May 24, 2012 at 4:56 PM, Metzler, David wrote:
> Two things:
>
> 1. Don't use db_select just because you're converting a module. You
> are adding overhead that doesn't need to be there. Event the authors of
> DBTNG agree with this statement. Stick to db_query unless you need to
> generate SQL dynamically.
>
I understand that db_select builds a string that is eventually passed
to MySQL but what overhead is added? Can you point to threads of
discussion?
> 2. Change the variable prior to binding it. Don't do token replacement
> at all. The idea is that the second parameter of the condition method
> should be that variable that contains the array, not a token replacement
> thing so if you're trying to make a wild card like, just concat like
> this:
>
> db_select('mytable', 'mt')
> ->fields('mt', array('myvar'))
> ->condition('mystring', '%' . $somrvariable . '%', LIKE)
> ->execute();
Ok, thanks. It just doesn't seem Drupalish, I would have expected an
optional 4th argument to provide token substitution. Shouldn't it be
check_plain($somevariable) then? Probably depends on how
$somevariable gets a value.
--
Earnie
-- https://sites.google.com/site/earnieboyd
More information about the support
mailing list