CrossPHP
  • Namespace
  • Class
  • Download

Namespaces

  • Cross
    • Auth
    • Cache
      • Driver
      • Request
    • Core
    • DB
      • Connecter
      • Drivers
      • SQLAssembler
    • Exception
    • Http
    • I
    • Lib
      • Document
    • Module
    • MVC
    • Runtime
  • None

Classes

  • Cross\Auth\CookieAuth
  • Cross\Auth\SessionAuth
  • Cross\Cache\Driver\FileCacheDriver
  • Cross\Cache\Driver\MemcacheDriver
  • Cross\Cache\Driver\RedisDriver
  • Cross\Cache\Request\FileCache
  • Cross\Cache\Request\Memcache
  • Cross\Cache\Request\RedisCache
  • Cross\Cache\RequestCache
  • Cross\Core\Annotate
  • Cross\Core\Application
  • Cross\Core\ArrayMap
  • Cross\Core\Config
  • Cross\Core\CrossArray
  • Cross\Core\Delegate
  • Cross\Core\FrameBase
  • Cross\Core\Helper
  • Cross\Core\HttpAuth
  • Cross\Core\Loader
  • Cross\Core\Rest
  • Cross\Core\Router
  • Cross\DB\Connecter\BaseConnecter
  • Cross\DB\Connecter\MySQLConnecter
  • Cross\DB\Connecter\PgSQLConnecter
  • Cross\DB\Connecter\SQLiteConnecter
  • Cross\DB\DBFactory
  • Cross\DB\Drivers\CouchDriver
  • Cross\DB\Drivers\MongoDriver
  • Cross\DB\Drivers\PDOSqlDriver
  • Cross\DB\SQLAssembler\MySQLAssembler
  • Cross\DB\SQLAssembler\PgSQLAssembler
  • Cross\DB\SQLAssembler\SQLAssembler
  • Cross\DB\SQLAssembler\SQLiteAssembler
  • Cross\Http\Request
  • Cross\Http\Response
  • Cross\Lib\Array2XML
  • Cross\Lib\Document\CallTree
  • Cross\Lib\Document\CallTreeToHTML
  • Cross\Lib\Document\HTML
  • Cross\Lib\StringToPHPStream
  • Cross\Module\SQLModule
  • Cross\MVC\Controller
  • Cross\MVC\Module
  • Cross\MVC\View
  • Cross\Runtime\ClosureContainer

Interfaces

  • Cross\I\CacheInterface
  • Cross\I\HttpAuthInterface
  • Cross\I\PDOConnecter
  • Cross\I\RequestCacheInterface
  • Cross\I\RouterInterface
  • Cross\I\SqlInterface

Exceptions

  • Cross\Exception\CacheException
  • Cross\Exception\CoreException
  • Cross\Exception\CrossException
  • Cross\Exception\FrontException

Functions

  • ascLogo
  • line
  • tBody
  • th
  • tHead
 1 <?php
 2 /**
 3  * Cross - a micro PHP 5 framework
 4  *
 5  * @link        http://www.crossphp.com
 6  * @license     MIT License
 7  */
 8 namespace Cross\DB\SQLAssembler;
 9 
10 /**
11  * @author wonli <wonli@live.com>
12  * Class PgSQLAssembler
13  * @package Cross\DB\SQLAssembler
14  */
15 class PgSQLAssembler extends SQLAssembler
16 {
17     /**
18      * 带分页功能的查询
19      *
20      * @param string $table 联合查询$table变量 $table = table_a a LEFT JOIN table_b b ON a.id=b.aid;
21      * @param string $fields 要查询的字段 所有字段的时候 $fields='*'
22      * @param string $where 查询条件
23      * @param int $order 排序
24      * @param array $page 分页参数 默认返回50条记录
25      * @param int|string $group_by
26      * @return mixed|void
27      * @throws \Cross\Exception\CoreException
28      */
29     public function find($table, $fields, $where, $order = 1, array &$page = array('p' => 1, 'limit' => 50), $group_by = 1)
30     {
31         $params = array();
32         $field_str = $this->parseFields($fields);
33         $where_str = $this->parseWhere($where, $params);
34         $order_str = $this->parseOrder($order);
35 
36         //offset 起始位置
37         $offset = $page['limit'] * ($page['p'] - 1);
38         if (1 !== $group_by) {
39             $group_str = $this->parseGroup($group_by);
40             $sql = "SELECT {$field_str} FROM {$table} WHERE {$where_str} GROUP BY {$group_str} ORDER BY {$order_str} LIMIT {$page['limit']} OFFSET {$offset}";
41         } else {
42             $sql = "SELECT {$field_str} FROM {$table} WHERE {$where_str} ORDER BY {$order_str} LIMIT {$page['limit']} OFFSET {$offset}";
43         }
44 
45         $this->setSQL($sql);
46         $this->setParams($params);
47     }
48 
49     /**
50      * PgSQL的limit如果有第二个参数, 那么和mysql的limit行为保持一致, 并且offset()不生效
51      *
52      * @param int $start
53      * @param bool|int $end
54      * @return string
55      */
56     public function limit($start, $end = false)
57     {
58         if ($end) {
59             $limit = max(1, (int)$end);
60             $offset = $limit * (max(1, (int)$start) - 1);
61 
62             $this->offset_is_valid = false;
63             return "LIMIT {$limit} OFFSET {$offset} ";
64         }
65 
66         $start = (int)$start;
67         return "LIMIT {$start} ";
68     }
69 }
70 
CrossPHP API documentation generated by ApiGen