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\SqliteDialectTrait;
 18: use Cake\Database\Driver;
 19: use Cake\Database\Query;
 20: use Cake\Database\Statement\PDOStatement;
 21: use Cake\Database\Statement\SqliteStatement;
 22: use PDO;
 23: 
 24: /**
 25:  * Class Sqlite
 26:  */
 27: class Sqlite extends Driver
 28: {
 29: 
 30:     use SqliteDialectTrait;
 31: 
 32:     /**
 33:      * Base configuration settings for Sqlite driver
 34:      *
 35:      * - `mask` The mask used for created database
 36:      *
 37:      * @var array
 38:      */
 39:     protected $_baseConfig = [
 40:         'persistent' => false,
 41:         'username' => null,
 42:         'password' => null,
 43:         'database' => ':memory:',
 44:         'encoding' => 'utf8',
 45:         'mask' => 0644,
 46:         'flags' => [],
 47:         'init' => [],
 48:     ];
 49: 
 50:     /**
 51:      * Establishes a connection to the database server
 52:      *
 53:      * @return bool true on success
 54:      */
 55:     public function connect()
 56:     {
 57:         if ($this->_connection) {
 58:             return true;
 59:         }
 60:         $config = $this->_config;
 61:         $config['flags'] += [
 62:             PDO::ATTR_PERSISTENT => $config['persistent'],
 63:             PDO::ATTR_EMULATE_PREPARES => false,
 64:             PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
 65:         ];
 66: 
 67:         $databaseExists = file_exists($config['database']);
 68: 
 69:         $dsn = "sqlite:{$config['database']}";
 70:         $this->_connect($dsn, $config);
 71: 
 72:         if (!$databaseExists && $config['database'] != ':memory:') {
 73:             //@codingStandardsIgnoreStart
 74:             @chmod($config['database'], $config['mask']);
 75:             //@codingStandardsIgnoreEnd
 76:         }
 77: 
 78:         if (!empty($config['init'])) {
 79:             foreach ((array)$config['init'] as $command) {
 80:                 $this->getConnection()->exec($command);
 81:             }
 82:         }
 83: 
 84:         return true;
 85:     }
 86: 
 87:     /**
 88:      * Returns whether php is able to use this driver for connecting to database
 89:      *
 90:      * @return bool true if it is valid to use this driver
 91:      */
 92:     public function enabled()
 93:     {
 94:         return in_array('sqlite', PDO::getAvailableDrivers());
 95:     }
 96: 
 97:     /**
 98:      * Prepares a sql statement to be executed
 99:      *
100:      * @param string|\Cake\Database\Query $query The query to prepare.
101:      * @return \Cake\Database\StatementInterface
102:      */
103:     public function prepare($query)
104:     {
105:         $this->connect();
106:         $isObject = $query instanceof Query;
107:         $statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
108:         $result = new SqliteStatement(new PDOStatement($statement, $this), $this);
109:         if ($isObject && $query->isBufferedResultsEnabled() === false) {
110:             $result->bufferResults(false);
111:         }
112: 
113:         return $result;
114:     }
115: 
116:     /**
117:      * {@inheritDoc}
118:      */
119:     public function supportsDynamicConstraints()
120:     {
121:         return false;
122:     }
123: }
124: 
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