Edit report at http://pear.php.net/bugs/bug.php?id=8668&edit=1

ID: 8668
Comment by: peter.bex@solide-ict.nl
Reported By: jose at infoviaweb dot com
Summary: Inconsistent return values for boolean types
Status: Bogus
Type: Bug
Package: MDB2
Operating System: irrelevant
Package Version: 2.2.2
PHP Version: Irrelevant
Roadmap Versions:
New Comment:

I think this bug is still relevant. The behaviour is inconsistent
because with MySQL, when using the createTable function from the manager
with a boolean type, the return value from fetchRow on that table is not
a boolean. With other database engines like PostgreSQL this is the

Since the createTable maps booleans to tinyint(1), I'd expect all
tinyint(1) columns to be mapped back to booleans too.

test script:
$conn->manager->createTable('foo', array('x' => array('type' =>
$conn->extended->autoExecute('foo', array('x' => true),
$res = $conn->query('SELECT x FROM foo', true);

expected result:
array(1) { ["x"] => bool(true) }

actual result:
array(1) { ["x"] => int(1) }

The proposed patch fixes this without requiring the user to interfere.
It should not break anything except rare cases where people are actually
asking for an integer field with length 1.

Previous Comments:

[2006-09-09 13:23:26] lsmith

You need to inform MDB2 of the types of your result columns if you want
to get datatype abstraction for selects:

$db->query($sql, array('boolean', 'boolean'));


[2006-09-08 17:45:59] jose at infoviaweb dot com

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:
require_once "MDB2.php";

$dsn = "mysql://someuser:somepassword@somehost/somedb";
//$dsn = "pgsql://someuser:somepassword@somehost/somedb";
/* the table tbl below is defined as:
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


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


Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
postedJan 21, '11 at 2:56p
activeJan 21, '11 at 2:56p

1 user in discussion

Peter Bex: 1 post



site design / logo © 2022 Grokbase