CodeIgniter pdo与postgres原生驱动对bool类型取值是不同的

CI版本2.1.3 ,对于返回bool类型值,比如

SELECT FALSE
如果用的是pdo驱动,那么取值结果也是bool类型。如果是postgres驱动,那么得到的是'f'字符串。

这个问题是PHP自己的问题:在老版本的pdo驱动发生过(好像是php5.1之前版本),现在的pdo已经修正。但postgres驱动看来没得到处理。

以下是php手册的信息:

strata_ranger at hotmail dot com (26-Aug-2008 11:01)
In a bit of follow-up to Luke's note about SQL booleans (this was a painful thing to learn the hard way), a relatively easy workaround is to typecase the boolean columns to integer inside the query, e.g:
<?php // Assuming 'foo' is a table column of type boolean
$res = pg_query("Select foo as foo1, foo::integer as foo2 from bar");
$data = pg_fetch_assoc($res);

if ($data['foo1']) echo 'foo1 = TRUE'; // Doesn't work as expected (string 't' and string 'f' both evaluate as TRUE)
if ($data['foo2']) echo 'foo2 = TRUE'; // Works as expected (string '0' evaluates as FALSE)
?>



转载于:https://my.oschina.net/mark35/blog/127462

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值