doumeng3188 2012-04-01 23:24
浏览 67

PHP PDO - bindValue PARAM_BOOL为字符串

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..

  • 写回答

1条回答 默认 最新

  • doudou5023 2012-04-01 23:32
    关注

    MySQL does not really have a boolean data type, the BOOLEAN keyword is just an alias of TINYINT(1).
    You must work it has an number where 1 = true and 0 = false. Check MySQL Data Types

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog