PHP PDO - bindValue PARAM_BOOL as string
Posted
by
PHP_guy
on Stack Overflow
See other posts from Stack Overflow
or by PHP_guy
Published on 2012-04-01T23:24:18Z
Indexed on
2012/04/01
23:29 UTC
Read the original article
Hit count: 158
I'm freaking out here and can't figure out what's wrong. I'm pretty new to PDO, but everything works in my code except for booleans which are sent as strings.
My code (simplified):
$sql = 'SELECT * FROM pages WHERE clean_url_slo = :clean_url_slo AND published = :published LIMIT 1';
$clean_url_slo = 'home';
$published = true;
Then I prepare stuff and execute it like this (simplified):
$stmt = $db->prepare($sql);
$stmt->bindValue(':clean_url_slo',$clean_url_slo,PDO::PARAM_STR);
$stmt->bindValue(':published',$published,PDO::PARAM_BOOL);
$stmt->execute();
And then here is what comes to mysql (from the mysql log - the query mysql received):
91 Query SELECT * FROM pages WHERE 1=1 AND clean_url_slo='domov' AND published='1' ORDER BY id desc LIMIT 1
As you can see, published is an integer - so always true, which is not OK. Why is that if I'm declaring it as a boolean?
using:
WAMP SERVER PHP version: 5.3.9 Mysql: 5.5.20
Many thanks for your help..
© Stack Overflow or respective owner