1 2/* 3 +------------------------------------------------------------------------+ 4 | Phalcon Framework | 5 +------------------------------------------------------------------------+ 6 | Copyright (c) 2011-2017 Phalcon Team (https://phalconphp.com) | 7 +------------------------------------------------------------------------+ 8 | This source file is subject to the New BSD License that is bundled | 9 | with this package in the file LICENSE.txt. | 10 | | 11 | If you did not receive a copy of the license and are unable to | 12 | obtain it through the world-wide-web, please send an email | 13 | to license@phalconphp.com so we can send you a copy immediately. | 14 +------------------------------------------------------------------------+ 15 | Authors: Andres Gutierrez <andres@phalconphp.com> | 16 | Eduar Carvajal <eduar@phalconphp.com> | 17 +------------------------------------------------------------------------+ 18 */ 19 20namespace Phalcon; 21 22use \PDO as Pdo; 23 24/** 25 * Phalcon\Db 26 * 27 * Phalcon\Db and its related classes provide a simple SQL database interface for Phalcon Framework. 28 * The Phalcon\Db is the basic class you use to connect your PHP application to an RDBMS. 29 * There is a different adapter class for each brand of RDBMS. 30 * 31 * This component is intended to lower level database operations. If you want to interact with databases using 32 * higher level of abstraction use Phalcon\Mvc\Model. 33 * 34 * Phalcon\Db is an abstract class. You only can use it with a database adapter like Phalcon\Db\Adapter\Pdo 35 * 36 *<code> 37 * use Phalcon\Db; 38 * use Phalcon\Db\Exception; 39 * use Phalcon\Db\Adapter\Pdo\Mysql as MysqlConnection; 40 * 41 * try { 42 * $connection = new MysqlConnection( 43 * [ 44 * "host" => "192.168.0.11", 45 * "username" => "sigma", 46 * "password" => "secret", 47 * "dbname" => "blog", 48 * "port" => "3306", 49 * ] 50 * ); 51 * 52 * $result = $connection->query( 53 * "SELECT * FROM robots LIMIT 5" 54 * ); 55 * 56 * $result->setFetchMode(Db::FETCH_NUM); 57 * 58 * while ($robot = $result->fetch()) { 59 * print_r($robot); 60 * } 61 * } catch (Exception $e) { 62 * echo $e->getMessage(), PHP_EOL; 63 * } 64 * </code> 65 */ 66abstract class Db 67{ 68 69 const FETCH_LAZY = \Pdo::FETCH_LAZY; 70 71 const FETCH_ASSOC = \Pdo::FETCH_ASSOC; 72 73 const FETCH_NAMED = \Pdo::FETCH_NAMED; 74 75 const FETCH_NUM = \Pdo::FETCH_NUM; 76 77 const FETCH_BOTH = \Pdo::FETCH_BOTH; 78 79 const FETCH_OBJ = \Pdo::FETCH_OBJ; 80 81 const FETCH_BOUND = \Pdo::FETCH_BOUND; 82 83 const FETCH_COLUMN = \Pdo::FETCH_COLUMN; 84 85 const FETCH_CLASS = \Pdo::FETCH_CLASS; 86 87 const FETCH_INTO = \Pdo::FETCH_INTO; 88 89 const FETCH_FUNC = \Pdo::FETCH_FUNC; 90 91 const FETCH_GROUP = \Pdo::FETCH_GROUP; 92 93 const FETCH_UNIQUE = \Pdo::FETCH_UNIQUE; 94 95 const FETCH_KEY_PAIR = \Pdo::FETCH_KEY_PAIR; 96 97 const FETCH_CLASSTYPE = \Pdo::FETCH_CLASSTYPE; 98 99 const FETCH_SERIALIZE = \Pdo::FETCH_SERIALIZE; 100 101 const FETCH_PROPS_LATE = \Pdo::FETCH_PROPS_LATE; 102 103 /** 104 * Enables/disables options in the Database component 105 */ 106 public static function setup(array! options) -> void 107 { 108 var escapeIdentifiers, forceCasting; 109 110 /** 111 * Enables/Disables globally the escaping of SQL identifiers 112 */ 113 if fetch escapeIdentifiers, options["escapeSqlIdentifiers"] { 114 globals_set("db.escape_identifiers", escapeIdentifiers); 115 } 116 117 /** 118 * Force cast bound values in the PHP userland 119 */ 120 if fetch forceCasting, options["forceCasting"] { 121 globals_set("db.force_casting", forceCasting); 122 } 123 } 124} 125