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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号