2009年1月31日星期六

Re: [fw-db] question about using a like statement in a select

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmErssACgkQ7bkAtAithusj1ACdGrX3nZMeK+jQZjSbTEyxjiRP
gXEAoMD0Y/aZLq+jz5l/UON2YNMTGrFw
=vIE2
-----END PGP SIGNATURE-----
water wrote:
> I'm having a problem using quoting and a like statement with somehting
> like this:
...
> $sql="select id, headline, body from node where body like
> '%".$this->_db->quote($query)."%'";
...
> Is there a way to call quote without it putting the surrounding single
> quotes.

As someone has already mentioned, you can use:

$this->_db->quote('%' . $query . '%');
(i.e put the wildcards inside the value.

> This is actually a larger issue (and I'd probably consider a bug
> for things like 'select * from menu where id=23' where adding a set of
> single quotes around 23 adds time to query processing on MySQL.

If the value you are passing to be quotes is an integer (and not just a
string representing an integer), it won't have quotes added around it:
eg.
$this->_db->quote((int) $value);

--

Brenton Alker

http://blog.tekerson.com/

没有评论: