note 108059 added to function.db2-prepare
| From: | gjarrige at six-axe dot fr | Date: | Mon, 26 Mar 2012 07:47:22 +0000 |
| Subject: | note 108059 added to function.db2-prepare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186816@lists.php.net to get a copy of this message | ||
I found a bug in the code I posted the 02-Mar-2012 at 04:20 for the scroll cursor technique : to
correct it, delete the line with the variable $max_offset.
For a better code :
public static function getScrollCursor($db, $sql, $args, $offset, $nblines_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 ;
}
$rows = array() ;
$st = db2_prepare ( $db, $sql, array('cursor' => DB2_SCROLLABLE) );
if (! $st) {
// place your error message here
$rows = null;
} else {
if (! db2_execute ( $st, $args )) {
// place your error message here
$rows = null;
} else {
for (
$tofetch = $nbl_par_page,
$row = db2_fetch_assoc ( $st, $offset);
$row !== false && $tofetch-- > 0;
$row = db2_fetch_assoc ( $st )
) {
$rows [] = $row;
}
}
db2_free_stmt($st);
}
return $rows ;
}
----
Server IP: 89.31.146.176
Probable Submitter: 82.235.78.154
----
Manual Page -- http://www.php.net/manual/en/function.db2-prepare.php
Edit -- https://master.php.net/note/edit/108059
Del: integrated -- https://master.php.net/note/delete/108059/integrated
Del: useless -- https://master.php.net/note/delete/108059/useless
Del: bad code -- https://master.php.net/note/delete/108059/bad+code
Del: spam -- https://master.php.net/note/delete/108059/spam
Del: non-english -- https://master.php.net/note/delete/108059/non-english
Del: in docs -- https://master.php.net/note/delete/108059/in+docs
Del: other reasons-- https://master.php.net/note/delete/108059
Reject -- https://master.php.net/note/reject/108059
Search -- https://master.php.net/manage/user-notes.php