Represents a prepared statement and, after the statement is executed, an associated result set.
Used query string.
Do not use BindParam inside a foreach loop use BindValue...
There are many references around for returning a refcursor from a pgSQL function using pg_query. All essentially boil down to executing the following single statement (or some variation of it):
begin; select yourFunction(params...); fetch all in cursorname; commit;
In PDO, this doesn't work because PDO won't allow multiple statements submitted as a single statement (due to SQL injection detection). Instead, try this or similar:
<?php
$sql = 'select yourFunction(params...)';
$db = new PDO('pgsql:dbname=yourDBname');
$db->beginTransaction();
$cmd = $db->prepare($sql);
if ($cmd->execute()) {
if ($query = $db->query('fetch all in cursorname')) {
...processing...
$query->closeCursor();
$cmd->closeCursor();
}
}
$db->commit();
?>
The query string used in a PDOStatement can be found using the (undocumented) property 'queryString'
<?php
//$stm is a prepared PDOStatement
print $stm->queryString
//example result
//SELECT firstname, lastname FROM user where id = :id
?>