php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37124 PostgreSQL Query Returns Resource id for Field Value
Submitted: 2006-04-18 17:54 UTC Modified: 2007-08-20 10:29 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:0 (0.0%)
From: ahaig at penguinmilitia dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.1.2 OS: Mac OS X 10.4.6
Private report: No CVE-ID: None
 [2006-04-18 17:54 UTC] ahaig at penguinmilitia dot net
Description:
------------
I'm using PostgreSQL 8.0.2

Query:

SELECT t.tgargs as args FROM pg_trigger t,pg_class c,pg_proc 
p WHERE t.tgenabled AND t.tgrelid = c.oid AND t.tgfoid = 
p.oid AND p.proname = 'RI_FKey_check_ins' AND c.relname 
=:tablename ORDER BY t.tgrelid

:tablename is bound to a var with the value 'tables' (for my 
particular case), and the same result occurs if I do not use 
binding and fill the string in myself with 'tables' instead 
of :tablename. When I run the query in psql it returns:

           args                                                   
------------------------------------------------------------
 tables_mainclassname_fkey\000tables\000classes
\000UNSPECIFIED\000mainclassname\000object_class\000
 tables_databasehandle_fkey\000tables\000databases
\000UNSPECIFIED\000databasehandle\000databasehandle\000
(2 rows)

Reproduce code:
---------------
$statement = $my_PDO_instance->prepare("SELECT t.tgargs as args FROM pg_trigger t,pg_class c,pg_proc p WHERE t.tgenabled AND t.tgrelid = c.oid AND t.tgfoid = p.oid AND p.proname = 'RI_FKey_check_ins' AND c.relname =:tablename ORDER BY t.tgrelid");
$statement->bindParam( ':tablename', $table );
$statement->execute();
print_r($statement->fetchAll());

The same thing occurs if I do:

foreach ( $my_PDO_instance->query("SELECT t.tgargs as args FROM pg_trigger t,pg_class c,pg_proc p WHERE t.tgenabled AND t.tgrelid = c.oid AND t.tgfoid = p.oid AND p.proname = 'RI_FKey_check_ins' AND c.relname =:tablename ORDER BY t.tgrelid") as $this_row ) {
     print_r($this_row);
}

Expected result:
----------------
Array ( [args] => tables_mainclassname_fkey\000tables
\000classes\000UNSPECIFIED\000mainclassname\000object_class
\000 ) Array ( [args] => tables_databasehandle_fkey\000tables
\000databases\000UNSPECIFIED\000databasehandle
\000databasehandle\000 )

Actual result:
--------------
Array ( [args] => Resource id #20 ) Array ( [args] => Resource 
id #21 )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-18 17:57 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-04-18 18:04 UTC] ahaig at penguinmilitia dot net
I guess I didn't include <?php ?> but I thought I included a 
full script. You will need to fill in $dsn $user and 
$password and $table as appropriate. 

$dsn should refer to a PostgreSQL DB, $table to a table with 
at least 1 foreign key.

Script:

<?php
$database = new PDO( $dsn, $user, $password );
$statement = $database->prepare("SELECT t.tgargs as args 
FROM pg_trigger t,pg_class c,pg_proc p WHERE t.tgenabled AND 
t.tgrelid = c.oid AND t.tgfoid = p.oid AND p.proname = 
'RI_FKey_check_ins' AND c.relname =:tablename ORDER BY 
t.tgrelid");
$table = '<name of table in database with at least 1 foreign 
key>';
$statement->bindParam( ':tablename', $table );
$statement->execute();
print_r($statement->fetchAll());
die("Here's my error!");
?>
 [2006-04-18 18:07 UTC] helly@php.net
What is the postgres data type you return here?
 [2006-04-18 18:10 UTC] ahaig at penguinmilitia dot net
pg_trigger.tgargs is a built in column in template1...

Looks like it's a bytea type.

(\d pg_trigger)
 [2006-04-19 09:58 UTC] tony2001@php.net
Assigned to the maintainer.
 [2006-04-19 14:44 UTC] wez@php.net
Sounds like a LOB type... tried using the streams functions to read it? (the resource is a stream).
 [2006-04-19 17:00 UTC] ahaig at penguinmilitia dot net
Just tried that. stream_get_line( $row['args'], 100 ) 
outputs:

tables_mainclassname_fkey
 [2006-04-19 17:01 UTC] ahaig at penguinmilitia dot net
Just tried that. stream_get_line( $row['args'], 100 ) 
outputs:

tables_mainclassname_fkey
 [2006-04-19 17:02 UTC] ahaig at penguinmilitia dot net
Trying to paste the information here about what I got trying 
to use a stream but for some reason it truncates it... Ended 
up with the same truncated post twice.
 [2006-04-19 21:45 UTC] tony2001@php.net
PDO_PGSQL returns bytea fields as streams by design.
Reclassified as docu problem.
 [2007-08-20 10:29 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"The bytea fields are returned as streams."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Sep 02 22:00:03 2025 UTC