Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- PDO::prepare and SELECT WHERE LIKE
August 23, 2006, 8:28 pm
rate this thread
I'm trying to get the following code to work:
$sql = 'SELECT name FROM ' . DB_TABLE_CITY . ' WHERE country_id = :countryId
AND name LIKE ":city%" LIMIT 10';
$sth = $dbh->prepare( $sql );
... LIKE "' . $city . '%" ...
Works fine, but PDO doesn't seem to recognize the :city variable with the
trailing % sign. How can I make this work so PDO recognizes :city?
Thanks in advance!
Re: PDO::prepare and SELECT WHERE LIKE
I've never used PDO but it seems you are using double quotes as string
separator in SQL, and that's not correct. All SQL dialects I know use
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com