note 94925 added to class.pdostatement
| From: | rosko at zeta dot org dot au | Date: | Thu, 03 Dec 2009 01:50:40 +0000 |
| Subject: | note 94925 added to class.pdostatement | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163514@lists.php.net to get a copy of this message | ||
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();
?>
----
Server IP: 117.104.162.229
Probable Submitter: 210.1.199.245 (proxied: 210.1.199.245)
----
Manual Page -- http://www.php.net/manual/en/class.pdostatement.php
Edit -- https://master.php.net/note/edit/94925
Del: integrated -- https://master.php.net/note/delete/94925/integrated
Del: useless -- https://master.php.net/note/delete/94925/useless
Del: bad code -- https://master.php.net/note/delete/94925/bad+code
Del: spam -- https://master.php.net/note/delete/94925/spam
Del: non-english -- https://master.php.net/note/delete/94925/non-english
Del: in docs -- https://master.php.net/note/delete/94925/in+docs
Del: other reasons-- https://master.php.net/note/delete/94925
Reject -- https://master.php.net/note/reject/94925
Search -- https://master.php.net/manage/user-notes.php