note 94925 deleted from class.pdostatement by cmb

From: Date: Wed, 15 Dec 2021 18:32:37 +0000
Subject: note 94925 deleted from class.pdostatement by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217374@lists.php.net to get a copy of this message
Note Submitter: rosko at zeta dot org dot au ---- 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(); ?>

« previous php.notes (#217374) next »