PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » MDB2 » Bug #8668

Inconsistent return values for boolean types

Details

Submitted2006-09-08 21:45 UTC
Fromjose at infoviaweb dot com
StatusBogus
PackageMDB2
PHP VersionIrrelevant
OSirrelevant
Roadmaps(Not assigned)

Comments

[2006-09-08 21:45 UTC] jose at infoviaweb dot com

Description:
------------
I'm using both MDB2_Driver_mysql and MDB2_Driver_pgsql.

When I query for a boolean field, the MDB2_Driver_pgsql returns 't' or 'f', but the MDB2_Driver_mysql returns 1 or 0. I haven't tested other drivers, but I suspect they show this same inconsistency. They should return either true, false or null, or 't', 'f', or 'null'; anything, as long as all drivers are consistent.

Versions used:

PHP 5.1.5 (from FreeBSD ports)
MySQL 5.1.11 (beta) (from FreeBSD ports)
PostgreSQL 8.1.4 (from FreeBSD ports)
MDB2 2.2.2 (from channel PEAR.PHP.NET)
MDB2_Driver_mysql 1.2.2 (from channel PEAR.PHP.NET)
MDB2_Driver_pgsql 1.2.2 (from channel PEAR.PHP.NE)

Test script:
---------------
<?php
require_once "MDB2.php";

$dsn = "mysql://someuser:somepassword@somehost/somedb";
//$dsn = "pgsql://someuser:somepassword@somehost/somedb";
/* the table tbl below is defined as:
CREATE TABLE tbl (
value1 bool,
value2 bool
);
INSERT INTO tbl (value1, value2) VALUES(true, false); */
$db =& MDB2::connect($dsn);
$sql = "SELECT * FROM tbl";
$rs = $db->query($sql);
// error check ommited
while($row = $rs->fetchRow()) {
echo "value1: " . $row[0]; // pgsql shows 't', mysql shows '1'
echo "\nvalue2: " . $row[1]; // pgsql shows 'f', mysql shows '0'
}
?>

Expected result:
----------------
value 1: true
value 2: false

or

value 1: t
value 2: f

consistently across all databases

Actual result:
--------------
mysql returns

value 1: 1
value 2: 0

pgsql returns

value 1: t
value 2: f