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)
?>



你可能感兴趣的:(CodeIgniter pdo与postgres原生驱动对bool类型取值是不同的)