From:             
Operating system: SuSE Linux 11 SP1
PHP version:      5.3.8
Package:          PostgreSQL related
Bug Type:         Bug
Bug description:pgsql module returns strings from SELECT queries for each 
unempty field

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) "cvbcvb...@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) "cvbcvb...@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"
}


-- 
Edit bug report at https://bugs.php.net/bug.php?id=60187&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=60187&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=60187&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=60187&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=60187&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=60187&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=60187&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=60187&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=60187&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=60187&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=60187&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=60187&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=60187&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=60187&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=60187&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=60187&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60187&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=60187&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=60187&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=60187&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=60187&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=60187&r=mysqlcfg

Reply via email to