note 107833 added to pdo.prepare

From: Date: Thu, 08 Mar 2012 12:00:54 +0000
Subject: note 107833 added to pdo.prepare
Groups: php.notes 
Request: Send a blank email to php-notes+get-186543@lists.php.net to get a copy of this message
Example of scroll cursor for DB2 for i5 (IBM i server), that I use in a abstract class : public static function getScrollCursor($db, $sql, $args, $offset, $nbl_by_page ) { if (!is_array($args)) { $args = array() ; } $offset = intval($offset) ; if ($offset <= 0) { $offset = 1 ; } $nbl_by_page = intval($nbl_by_page); if ($nbl_by_page <= 0) { $nbl_by_page = 10 ; } $sql = trim ($sql ); $rows = array (); try { $st = $db->prepare ( $sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $ok = $st->execute ( $args ); if ($ok) { for ( $tofetch = $nbl_by_page, $row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, $offset); $row !== false && $tofetch-- > 0; $row = $st->fetch(PDO::FETCH_ASSOC) ) { $rows [] = $row; } } else { $rows = null; } unset ( $st ); return $rows; } catch ( Exception $e ) { // place your error code here; } } You'll find a similar example in the PHP.net site, for the function "prepare" of the "ibm_db2" library. The scroll cursor technique is more efficient on very big tables than the "full SQL" technique presented below : SELECT foo.* FROM ( SELECT row_number() over (ORDER BY TABLE_NAME) as rn, A.* FROM YOURLIB/YOURTABLE A WHERE YOU_COL1 = ? AND YOUR_COL2 = ? ... ) AS foo WHERE foo.rn BETWEEN ? AND ? ---- Server IP: 195.221.21.36 Probable Submitter: 212.155.199.228 ---- Manual Page -- http://www.php.net/manual/en/pdo.prepare.php Edit -- https://master.php.net/note/edit/107833 Del: integrated -- https://master.php.net/note/delete/107833/integrated Del: useless -- https://master.php.net/note/delete/107833/useless Del: bad code -- https://master.php.net/note/delete/107833/bad+code Del: spam -- https://master.php.net/note/delete/107833/spam Del: non-english -- https://master.php.net/note/delete/107833/non-english Del: in docs -- https://master.php.net/note/delete/107833/in+docs Del: other reasons-- https://master.php.net/note/delete/107833 Reject -- https://master.php.net/note/reject/107833 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186543) next »