|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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 )
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 14:00:01 2025 UTC |
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!"); ?>