CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Mysql
  • Postgres
  • Sqlite
  • Sqlserver

Traits

  • PDODriverTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Database\Driver;
 16: 
 17: use Cake\Database\Dialect\PostgresDialectTrait;
 18: use Cake\Database\Driver;
 19: use PDO;
 20: 
 21: /**
 22:  * Class Postgres
 23:  */
 24: class Postgres extends Driver
 25: {
 26: 
 27:     use PostgresDialectTrait;
 28: 
 29:     /**
 30:      * Base configuration settings for Postgres driver
 31:      *
 32:      * @var array
 33:      */
 34:     protected $_baseConfig = [
 35:         'persistent' => true,
 36:         'host' => 'localhost',
 37:         'username' => 'root',
 38:         'password' => '',
 39:         'database' => 'cake',
 40:         'schema' => 'public',
 41:         'port' => 5432,
 42:         'encoding' => 'utf8',
 43:         'timezone' => null,
 44:         'flags' => [],
 45:         'init' => [],
 46:     ];
 47: 
 48:     /**
 49:      * Establishes a connection to the database server
 50:      *
 51:      * @return bool true on success
 52:      */
 53:     public function connect()
 54:     {
 55:         if ($this->_connection) {
 56:             return true;
 57:         }
 58:         $config = $this->_config;
 59:         $config['flags'] += [
 60:             PDO::ATTR_PERSISTENT => $config['persistent'],
 61:             PDO::ATTR_EMULATE_PREPARES => false,
 62:             PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
 63:         ];
 64:         if (empty($config['unix_socket'])) {
 65:             $dsn = "pgsql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
 66:         } else {
 67:             $dsn = "pgsql:dbname={$config['database']}";
 68:         }
 69: 
 70:         $this->_connect($dsn, $config);
 71:         $this->_connection = $connection = $this->getConnection();
 72:         if (!empty($config['encoding'])) {
 73:             $this->setEncoding($config['encoding']);
 74:         }
 75: 
 76:         if (!empty($config['schema'])) {
 77:             $this->setSchema($config['schema']);
 78:         }
 79: 
 80:         if (!empty($config['timezone'])) {
 81:             $config['init'][] = sprintf('SET timezone = %s', $connection->quote($config['timezone']));
 82:         }
 83: 
 84:         foreach ($config['init'] as $command) {
 85:             $connection->exec($command);
 86:         }
 87: 
 88:         return true;
 89:     }
 90: 
 91:     /**
 92:      * Returns whether php is able to use this driver for connecting to database
 93:      *
 94:      * @return bool true if it is valid to use this driver
 95:      */
 96:     public function enabled()
 97:     {
 98:         return in_array('pgsql', PDO::getAvailableDrivers());
 99:     }
100: 
101:     /**
102:      * Sets connection encoding
103:      *
104:      * @param string $encoding The encoding to use.
105:      * @return void
106:      */
107:     public function setEncoding($encoding)
108:     {
109:         $this->connect();
110:         $this->_connection->exec('SET NAMES ' . $this->_connection->quote($encoding));
111:     }
112: 
113:     /**
114:      * Sets connection default schema, if any relation defined in a query is not fully qualified
115:      * postgres will fallback to looking the relation into defined default schema
116:      *
117:      * @param string $schema The schema names to set `search_path` to.
118:      * @return void
119:      */
120:     public function setSchema($schema)
121:     {
122:         $this->connect();
123:         $this->_connection->exec('SET search_path TO ' . $this->_connection->quote($schema));
124:     }
125: 
126:     /**
127:      * {@inheritDoc}
128:      */
129:     public function supportsDynamicConstraints()
130:     {
131:         return true;
132:     }
133: }
134: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs