• PHP oracle分页


    oracle分页

    function getall($query, $start=0, $rows=-1)
            {
                 $this->dbh = oci_connect('aaa','mmm',"(DEscriptION=(ADDRESS=(PROTOCOL =TCP)(HOST=bbb)(PORT = 1521))(CONNECT_DATA =(SID=vvv)))");       
                 $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;
            }
            /**
            * 获取分页数
            *
            * $query  string   查询语句
            * $total  int    总条数
            * $page  int    页数
            * $rows  int    每页显示数
            * @return integer  总行数
            */
            function 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);
            }
            /**
            * 获取一个查询的总行数
            *
            * $string $sql 查询语句
            *
            * return integer 总行数
            */
            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 (empty($result))
                 $row = array();
                 else
                 $row = $result[0];
                 unset($result);
                 return $row;
            }
    
            public function test()
            {
                $sql = 'SELECT * FROM TBL_ACCOUNT_CHANNEL ';
                $page = 10;
                $total = $this->getcount($sql);
                $page_number = 10;
                $result = $this->getpage($sql,$total,$page,$page_number);
                print_r($result);
            }
  • 相关阅读:
    electron 打包生成exe文件
    Mac M1芯片 docker搭建php环境
    dockercompose设定网段和自动生成网段
    关于Spring boot 文件上传的文件
    linux安装ftp
    境外直播源
    Qt Visual Studio插件下载
    QImage和QPixmap转Base64字符串
    VS编译Qt项目报错:fatal error C1189: #error: Unsupported architecture
    Android进root权限查看app中的文件
  • 原文地址:https://www.cnblogs.com/feiwu123/p/5416871.html
Copyright © 2020-2023  润新知