#php #mysql #pdo prepare and single quotes #gotcha

i suspect that php pdo prepare may be double escaping single quotes in your sql string so replace single quotes with double quotes

FAILS

$sql = <<<EOT
    select * from cars where colour='red'
EOT;
$stm = $db->prepare($sql);

WORKS

$sql = <<<EOT
    select * from cars where colour="red"
EOT;
$stm = $db->prepare($sql);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s