473,396 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PDO::prepare and SELECT WHERE LIKE

Hi,

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 );
etc...

Using:

.... 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!
Aug 23 '06 #1
2 3453
*** amygdala escribió/wrote (Wed, 23 Aug 2006 22:28:26 +0200):
$sql = 'SELECT name FROM ' . DB_TABLE_CITY . ' WHERE country_id = :countryId
AND name LIKE ":city%" LIMIT 10';
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
single quotes.
--
-+ 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
--
Aug 23 '06 #2

"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.comschreef in bericht
news:12******************************@40tude.net.. .
*** amygdala escribió/wrote (Wed, 23 Aug 2006 22:28:26 +0200):
>$sql = 'SELECT name FROM ' . DB_TABLE_CITY . ' WHERE country_id =
:countryId
AND name LIKE ":city%" LIMIT 10';

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
single quotes.
No, sorry, that's not it. Double quotes work fine with mysql on my system
(wamp). I tried single quotes too though (escaped in this case of course).
Aug 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James | last post by:
Hey everyone... I'm having an issue with a seemingly simple piece of PHP/MySQL I have a stored procedure in MySQL5 as such: SQL: -------------- DELIMITER $$; DROP PROCEDURE IF EXISTS...
2
by: amygdala | last post by:
Hi, I am having an awful lot of trouble of getting the PDO layer to work properly. example code: ----------------- $tmpArray = array ( ':table' ='session', ':id' ='4364564574574576',
3
by: amygdala | last post by:
Hi, Can anyone recommend some extensive PDO documentation? Especially documentation that describes PDO's security capabilities. For instance what measurements does the PDO::prepare take to...
1
by: gp | last post by:
****************************************************************************************************************************** Catchable fatal error: Object of class stdClass could not be...
4
by: macca | last post by:
Hi, quite new to design patterns so please humour me. I'm having a little trouble figuring out how to use the singleton pattern to create a database PDO object that I can then refer to in my...
0
by: WebCM | last post by:
PDO offers 3 modes of displaying errors: - silent mode - no errors - warnings - Warning: - exceptions - Exception: Which of them is the fastest and the most adequate for applications like CMS...
3
by: Gilles Ganault | last post by:
Hi APC doesn't like it when I store the output of a SELECT: === include("apc.php"); $dbh = new PDO("sqlite:./test.sqlite"); $sql = "CREATE TABLE IF NOT EXISTS mytable (name TEXT)";
3
by: FeelLikeANut | last post by:
I have the code below. First there is a transaction where I select data. I wrapped it in an explicit transaction because in my real program I run a couple different selects. Nevertheless, the...
3
by: 123betty | last post by:
Could you please help me: $sql = "SELECT qualityId FROM quality WHERE qualityName = 'VVS'"; $r = $d->selectQueryQuality($sql); $sql = "INSERT INTO stones (size, price, qualityId)...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.