php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47051 pg_fetch_object does not convert to literal PHP booleans
Submitted: 2009-01-09 13:24 UTC Modified: 2020-02-13 17:10 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: germ dot van dot eck at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: PostgreSQL related
PHP Version: 5.2.8 OS: Linux, Ubuntu 8.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: germ dot van dot eck at gmail dot com
New email:
PHP Version: OS:

 

 [2009-01-09 13:24 UTC] germ dot van dot eck at gmail dot com
Description:
------------
Postgresql booleans are internally stored as either 'f' or 't' (False or True).
On retrieval using pg_fetch_object, they are simply retrieved as PHP strings, rather than either 0 or 1, or even better, false or true.
This causes that postgresql.
I am not sure, but I think in the data returned by the server, there is metadata explaining the field types and so they could be automatically converted to PHP bools.
This is from a bugreport and related forum topic that was made for the CodeIgniter framework.
Bugreport (slighly unrelated CI bug, but this issue was discussed in the comments):
http://codeigniter.com/bug_tracker/bug/6303/
Forum topic:
http://codeigniter.com/forums/viewthread/101001/


Reproduce code:
---------------
<?php
$conn_string = "host=testserver dbname=testdb user=foo password=bar";
$dbconn = pg_connect($conn_string);
pg_query('CREATE TABLE test(test boolean)');
pg_query('INSERT INTO test(test) VALUES(TRUE)');
$res = pg_query('SELECT * FROM test');
$obj = pg_fetch_object($res);
echo "\n".$obj->test."\n";
pg_query('DROP TABLE test');
?>


Expected result:
----------------
1

Actual result:
--------------
t

Patches

pgsql_convert_boolean_and_integer_in_results (last revision 2012-01-27 01:33 UTC by morphunreal at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-09 13:30 UTC] germ dot van dot eck at gmail dot com
I did not complete my sentence...
"This causes that postgresql."
should be
"This causes that postgresql's booleans are not very usable in PHP".
 [2009-01-11 01:05 UTC] felipe@php.net
This isn't a bug, it's only as pgsql works.

Moved to Feature/Change request.
 [2011-01-01 23:10 UTC] jani@php.net
-Package: Feature/Change Request +Package: PostgreSQL related
 [2012-01-26 13:17 UTC] morphunreal at gmail dot com
I have created & submitted a patch that allows pgsql to return booleans and integers for all fetches.

to test / use->
- get current source for php/ext/pgsql
- apply patch
- phpize
- ./configure --with-pgsql=/path/to/pgsql/c-api
- make
- stop web server
- copy modules/pgsql.so over existing one
- add to /etc/php.d/pgsql.conf
pgsql.convert_boolean_type = 1
pgsql.convert_integer_type = 1
- start web server
 [2012-03-29 09:59 UTC] yohgaki@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: yohgaki
 [2013-06-29 04:02 UTC] yohgaki@php.net
I've verified current PostgreSQL git source.

It seems they have been removed static OID definition from their code. This means 
that OID of certain type may change version to version.

I'll verify postgresql developers if it's safe to assume OID of basic types would 
not change.
 [2017-10-24 08:02 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: yohgaki +Assigned To:
 [2020-02-13 17:10 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2020-02-13 17:10 UTC] cmb@php.net
Request #78855 is about the same feature, and since that has a
more recent PR attached, I'm closing this ticket as duplicate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 00:01:30 2024 UTC