php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60187 pgsql module returns strings from SELECT queries for each unempty field
Submitted: 2011-11-01 10:47 UTC Modified: 2015-02-03 06:51 UTC
Votes:4
Avg. Score:3.5 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: gatekeeper dot mail at gmail dot com Assigned: yohgaki (profile)
Status: Assigned Package: PostgreSQL related
PHP Version: 5.3.8 OS: SuSE Linux 11 SP1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-11-01 10:47 UTC] gatekeeper dot mail at gmail dot com
Description:
------------
pgsql modules returns all non-null values as String type data instead of corresponding php datatype when applicable. PDO is not affected though. 

Test script:
---------------
# CREATE TABLE netusers (id bigserial NOT NULL, firstname character varying NOT NULL, middlename character varying NOT NULL DEFAULT ''::character varying, lastname character varying NOT NULL DEFAULT ''::character varying, company_id integer NOT NULL DEFAULT 0, department_id integer NOT NULL DEFAULT 0, connect_date date NOT NULL DEFAULT now(), disconnect_date date, login character varying NOT NULL DEFAULT ''::character varying, password character varying NOT NULL DEFAULT ''::character varying, email text NOT NULL DEFAULT ''::character varying, email_alias text NOT NULL DEFAULT ''::character varying, computer character varying NOT NULL DEFAULT ''::character varying, ipaddr bigint NOT NULL DEFAULT 0, macaddr bigint NOT NULL DEFAULT 0, inet_date date, phone_local text NOT NULL DEFAULT ''::text, phone_global text NOT NULL DEFAULT ''::text, comment text, cable_id bigint NOT NULL DEFAULT 0, CONSTRAINT netusers_pk PRIMARY KEY (id )) WITH (OIDS=FALSE);
# Put a row into that table with some random (but according to columns' datatype) data
<?php
$dsn = 'pgsql:host=host;port=5432;dbname=testdb';
$username = 'test';
$password = 'testpw';

$conn = new PDO($dsn, $username, $password);
$stmt = $conn->query('select * from netusers');
$o = $stmt->fetchObject();
//This gets appropriate datatypes for all non-null fields (int for int, string for string etc... Except (hell yeah!) arrays)
var_dump($o);
//*************************
$conn2 = pg_connect("host=host port=5432 dbname=testdb user=test password=testpw");
$stmt2 = pg_query($conn2, "SELECT * FROM netusers");
$o2 = pg_fetch_object($stmt2);
//This gets an object with every non-null property having datatype string
var_dump($o2);


Expected result:
----------------
# This is the PDO output part of the test script
object(stdClass)#3 (20) {
  ["id"]=>
  int(0)
  ["firstname"]=>
  string(3) "asd"
  ["middlename"]=>
  string(7) "dasfsdf"
  ["lastname"]=>
  string(8) "sdafdsdf"
  ["company_id"]=>
  int(0)
  ["department_id"]=>
  int(0)
  ["connect_date"]=>
  string(10) "2011-10-28"
  ["disconnect_date"]=>
  NULL
  ["login"]=>
  string(6) "asfdfg"
  ["password"]=>
  string(6) "dfsdfg"
  ["email"]=>
  string(22) "cvbcvbcvb@xcvxcvxcv.as"
  ["email_alias"]=>
  string(0) ""
  ["computer"]=>
  string(5) "sdasd"
  ["ipaddr"]=>
  int(0)
  ["macaddr"]=>
  int(0)
  ["inet_date"]=>
  NULL
  ["phone_local"]=>
  string(6) "234234"
  ["phone_global"]=>
  string(0) ""
  ["comment"]=>
  string(14) "svsdfgsdfgsdfg"
  ["cable_id"]=>
  int(0)
}


Actual result:
--------------
# This is the PGSQL output part of the test script
object(stdClass)#4 (20) {
  ["id"]=>
  string(1) "0"
  ["firstname"]=>
  string(3) "asd"
  ["middlename"]=>
  string(7) "dasfsdf"
  ["lastname"]=>
  string(8) "sdafdsdf"
  ["company_id"]=>
  string(1) "0"
  ["department_id"]=>
  string(1) "0"
  ["connect_date"]=>
  string(10) "2011-10-28"
  ["disconnect_date"]=>
  NULL
  ["login"]=>
  string(6) "asfdfg"
  ["password"]=>
  string(6) "dfsdfg"
  ["email"]=>
  string(22) "cvbcvbcvb@xcvxcvxcv.as"
  ["email_alias"]=>
  string(0) ""
  ["computer"]=>
  string(5) "sdasd"
  ["ipaddr"]=>
  string(1) "0"
  ["macaddr"]=>
  string(1) "0"
  ["inet_date"]=>
  NULL
  ["phone_local"]=>
  string(6) "234234"
  ["phone_global"]=>
  string(0) ""
  ["comment"]=>
  string(14) "svsdfgsdfgsdfg"
  ["cable_id"]=>
  string(1) "0"
}


Patches

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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-27 03:35 UTC] morphunreal at gmail dot com
same patch that I have created for bug #47051 (except that issue was from 2009).

for backwards compatibility i have had to add the options 
pgsql.convert_boolean_type & pgsql.convert_integer_type


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:58 UTC] yohgaki@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: yohgaki
 [2015-02-03 06:51 UTC] yohgaki@php.net
-Type: Bug +Type: Feature/Change Request
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC