Examples of Oracle paging functions implemented by PHP, phporacle pagination Instance _php tutorial

Source: Internet
Author: User
Tags php database

Examples of Oracle paging functions implemented by PHP, Phporacle page Instances


This article describes the Oracle paging function implemented by PHP. Share to everyone for your reference, as follows:

MySQL has limit, paging, we can use limit 30, 40, and Oracle has no limit, the other way to replace the--rownum.

First, the underlying method

/** * Data connection */function Connect ($db _user, $db _pwd, $db _name, $db _nls) {$this-&GT;DBH = Oci_connect ($db _user, $db _pwd, $db _na Me, $db _nls);} function GetAll ($query, $start =0, $rows =-1) {$this-&GT;DBH = emptyempty ($this->dbh)? $this->connect (): $this- >dbh; $this->sth = Oci_parse ($this->dbh, $query); Oci_execute ($this->sth, Oci_default) or $this->error ($this->sth, $query); Oci_fetch_all ($this->sth, $res, $start, $rows, OCI_FETCHSTATEMENT_BY_ROW+OCI_ASSOC); return $res;} /*** Get Pagination * * $query string query statement * $total int total number of bars * $page int pages * $rows int displayed per page * @return integer row number */funct Ion GetPage ($query, $total, $page, $rows =var_pagenav_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);} /*** gets the total number of rows for a query * * $string $sql Query statement * * Return integer Total row number */function GetCount ($sql) {$subSQL = ' select count (*) '. STRISTR ($s QL, ' 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;}

Main two methods I write a little note

Ii. Method of Invocation

$total = $this->db->getcount ($sql); $result = $this->db->getpage ($sql, $total, $page, $page _number);

The above is just a part of the code, but also the core.

For more information about PHP database operations interested readers can view the site topics: "PHP common Database Operation skills Summary", "PHP based on PDO Operation Database skills summary" and "Php+mysql Database Operation Primer".

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Php+oracle Pagination Class
    • How PHP connects to Oracle database and query data
    • PHP handles Oracle's CLOB instances
    • PHP connection to Oracle database under Linux
    • WIN7 64-bit system PHP connection to Oracle Database
    • PHP reads the contents of a text file and displays it in pages
    • PHP custom pagination Class Complete instance
    • Two All-purpose PHP paging class
    • PHP 3 ways to achieve paging functionality
    • Detailed Php+ajax No Refresh paging implementation method

http://www.bkjia.com/PHPjc/1095683.html www.bkjia.com true http://www.bkjia.com/PHPjc/1095683.html techarticle PHP Implementation of the Oracle paging function instance, phporacle Pagination Example This article describes the PHP implementation of the Oracle paging function. Share to everyone for your reference, specifically as follows: MySQL has limit, points ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.