|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-02-03 10:01 UTC] mbeccati@php.net
-Type: Bug
+Type: Documentation Problem
[2015-02-03 10:01 UTC] mbeccati@php.net
[2015-02-04 02:34 UTC] aharvey@php.net
[2015-02-04 02:34 UTC] aharvey@php.net
-Status: Open
+Status: Closed
-Package: PDO PgSQL
+Package: Documentation problem
-Assigned To:
+Assigned To: aharvey
[2015-02-04 02:34 UTC] aharvey@php.net
[2015-02-04 02:34 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 13:00:01 2025 UTC |
Description: ------------ PostgreSQL has proper support for boolean fields. Boolean database fields are returned to PHP as boolean values. Additionally, when using fetchColumn() it is often useful to know if no rows were returned. PDO reports this by returning the value false. There is a conflict here as false is now overloaded to represent both "no rows returned" and "column value false". These are two distinct cases that may need to be handled separately. $ php --version PHP 5.5.20 (cli) (built: Dec 18 2014 05:55:32) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies with Xdebug v2.2.6, Copyright (c) 2002-2014, by Derick Rethans The following script demonstrates this behavior. Test script: --------------- <?php $db = new PDO('pgsql:dbname=test', 'postgres'); $db->exec('DROP TABLE IF EXISTS test_table'); $db->exec('CREATE TABLE test_table (field boolean)'); $stmt = $db->query('SELECT * FROM test_table'); var_dump($stmt->fetchColumn()); $db->exec('INSERT INTO test_table VALUES (FALSE)'); $stmt = $db->query('SELECT * FROM test_table'); var_dump($stmt->fetchColumn()); Expected result: ---------------- I expect the two var_dumps() to return different values, but they do not. (Alternatively, if an exception was thrown that would also work, but PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION does not make this happen.) Actual result: -------------- bool(false) bool(false) The two var_dump()s are identical making it difficult to know if no rows were returned or the value false was returned.