This article mainly Introduces oracle paging functions implemented by PHP, and analyzes the paging operations implemented by PHP for oracle databases using rownum instead of limit in MySQL using examples, for more information about oracle paging functions implemented by PHP, see the example in this article. 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.