Oracle paging function instances implemented by PHP and phporacle paging instances. PHP-implemented oracle paging function instance. phporacle paging instance this article describes the oracle paging function implemented by PHP. For your reference, we will share the following details: mysql has limit, which is an oracle paging function instance implemented by PHP and a phporacle paging instance.
This article describes the oracle paging functions implemented by PHP. We will share this with you for your reference. The details are as follows:
Mysql has limit. When paging, we can use limit, while oracle does not have limit. we can use other methods to replace -- rownum.
I. underlying methods
/*** Data connection */function connect ($ db_user, $ db_pwd, $ db_name, $ db_nls) {$ this-> dbh = oci_connect ($ db_user, $ db_pwd, $ db_name, $ db_nls);} function getall ($ query, $ start = 0, $ rows =-1) {$ this-> dbh = emptyempty ($ this-> dbh )? $ This-> connect (): $ this-> dbh; $ this-> something = oci_parse ($ this-> dbh, $ query); oci_execute ($ this-> something, OCI_DEFAULT) or $ this-> error ($ this-> something, $ query); oci_fetch_all ($ this-> something, $ res, $ start, $ rows, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC); return $ res ;} /*** retrieve the number of pages ** $ query string query statement * $ total int total number of pages * $ page int number of pages * $ number of rows int displayed per page * @ return integer total number of rows * /function getpage ($ query, $ total, $ page, $ rows = VAR_PA GENAV_ROWS) {$ start_row = ($ page-1) * $ rows + 1; $ start_row = $ start_row> $ total? 1: $ start_row; $ end_row = $ start_row + $ rows-1; $ end_row = $ end_row> $ total? $ Total: $ end_row; $ query = "SELECT * FROM (select rownum as row_num, r. * FROM ($ query) r where rownum <= $ end_row) WHERE $ start_row <= row_num "; return $ this-> getall ($ query );} /*** get the total number of rows for a query ** $ string $ SQL query statement ** return integer total number of rows */function getcount ($ SQL) {$ subSQL = 'SELECT count (*)'. stristr ($ SQL, 'from'); return $ this-> getone ($ subSQL);} function getone ($ query) {$ row = $ this-> getrow ($ query); if (is_array ($ row) $ one = current ($ row); else $ one = ''; unset ($ row); return $ one;} function getrow ($ query) {if (false === stripos ($ query, 'Count (')) {if (false = stripos ($ query, 'where') {$ query. = 'Where ROWNUM = 1';} else {$ query. = 'and rownum = 1'; }}$ result = $ this-> getall ($ query, 0, 1); if (emptyempty ($ result )) $ row = array (); else $ row = $ result [0]; unset ($ result); return $ row ;}
There are two main methods. I want to write some comments.
II. call method
$total = $this->db->getcount($sql);$result = $this->db->getpage($sql,$total,$page,$page_number);
The above only posts part of the code, which is also the core.