Db
1 year ago
Session
1 year ago
Config.php
2 years ago
Db.php
2 years ago
Exception.php
1 year ago
LICENSE.txt
6 years ago
Registry.php
2 years ago
Session.php
1 year ago
Version.php
2 years ago
Db.php
268 lines
| 1 | <?php |
| 2 | |
| 3 | namespace { |
| 4 | /** |
| 5 | * Zend Framework |
| 6 | * |
| 7 | * LICENSE |
| 8 | * |
| 9 | * This source file is subject to the new BSD license that is bundled |
| 10 | * with this package in the file LICENSE.txt. |
| 11 | * It is also available through the world-wide-web at this URL: |
| 12 | * http://framework.zend.com/license/new-bsd |
| 13 | * If you did not receive a copy of the license and are unable to |
| 14 | * obtain it through the world-wide-web, please send an email |
| 15 | * to license@zend.com so we can send you a copy immediately. |
| 16 | * |
| 17 | * @category Zend |
| 18 | * @package Zend_Db |
| 19 | * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) |
| 20 | * @license http://framework.zend.com/license/new-bsd New BSD License |
| 21 | * @version $Id: Db.php 24417 2011-08-28 10:15:47Z padraic $ |
| 22 | */ |
| 23 | /** |
| 24 | * Class for connecting to SQL databases and performing common operations. |
| 25 | * |
| 26 | * @category Zend |
| 27 | * @package Zend_Db |
| 28 | * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) |
| 29 | * @license http://framework.zend.com/license/new-bsd New BSD License |
| 30 | */ |
| 31 | class Zend_Db |
| 32 | { |
| 33 | /** |
| 34 | * Use the PROFILER constant in the config of a Zend_Db_Adapter. |
| 35 | */ |
| 36 | const PROFILER = 'profiler'; |
| 37 | /** |
| 38 | * Use the CASE_FOLDING constant in the config of a Zend_Db_Adapter. |
| 39 | */ |
| 40 | const CASE_FOLDING = 'caseFolding'; |
| 41 | /** |
| 42 | * Use the FETCH_MODE constant in the config of a Zend_Db_Adapter. |
| 43 | */ |
| 44 | const FETCH_MODE = 'fetchMode'; |
| 45 | /** |
| 46 | * Use the AUTO_QUOTE_IDENTIFIERS constant in the config of a Zend_Db_Adapter. |
| 47 | */ |
| 48 | const AUTO_QUOTE_IDENTIFIERS = 'autoQuoteIdentifiers'; |
| 49 | /** |
| 50 | * Use the ALLOW_SERIALIZATION constant in the config of a Zend_Db_Adapter. |
| 51 | */ |
| 52 | const ALLOW_SERIALIZATION = 'allowSerialization'; |
| 53 | /** |
| 54 | * Use the AUTO_RECONNECT_ON_UNSERIALIZE constant in the config of a Zend_Db_Adapter. |
| 55 | */ |
| 56 | const AUTO_RECONNECT_ON_UNSERIALIZE = 'autoReconnectOnUnserialize'; |
| 57 | /** |
| 58 | * Use the INT_TYPE, BIGINT_TYPE, and FLOAT_TYPE with the quote() method. |
| 59 | */ |
| 60 | const INT_TYPE = 0; |
| 61 | const BIGINT_TYPE = 1; |
| 62 | const FLOAT_TYPE = 2; |
| 63 | /** |
| 64 | * PDO constant values discovered by this script result: |
| 65 | * |
| 66 | * $list = array( |
| 67 | * 'PARAM_BOOL', 'PARAM_NULL', 'PARAM_INT', 'PARAM_STR', 'PARAM_LOB', |
| 68 | * 'PARAM_STMT', 'PARAM_INPUT_OUTPUT', 'FETCH_LAZY', 'FETCH_ASSOC', |
| 69 | * 'FETCH_NUM', 'FETCH_BOTH', 'FETCH_OBJ', 'FETCH_BOUND', |
| 70 | * 'FETCH_COLUMN', 'FETCH_CLASS', 'FETCH_INTO', 'FETCH_FUNC', |
| 71 | * 'FETCH_GROUP', 'FETCH_UNIQUE', 'FETCH_CLASSTYPE', 'FETCH_SERIALIZE', |
| 72 | * 'FETCH_NAMED', 'ATTR_AUTOCOMMIT', 'ATTR_PREFETCH', 'ATTR_TIMEOUT', |
| 73 | * 'ATTR_ERRMODE', 'ATTR_SERVER_VERSION', 'ATTR_CLIENT_VERSION', |
| 74 | * 'ATTR_SERVER_INFO', 'ATTR_CONNECTION_STATUS', 'ATTR_CASE', |
| 75 | * 'ATTR_CURSOR_NAME', 'ATTR_CURSOR', 'ATTR_ORACLE_NULLS', |
| 76 | * 'ATTR_PERSISTENT', 'ATTR_STATEMENT_CLASS', 'ATTR_FETCH_TABLE_NAMES', |
| 77 | * 'ATTR_FETCH_CATALOG_NAMES', 'ATTR_DRIVER_NAME', |
| 78 | * 'ATTR_STRINGIFY_FETCHES', 'ATTR_MAX_COLUMN_LEN', 'ERRMODE_SILENT', |
| 79 | * 'ERRMODE_WARNING', 'ERRMODE_EXCEPTION', 'CASE_NATURAL', |
| 80 | * 'CASE_LOWER', 'CASE_UPPER', 'NULL_NATURAL', 'NULL_EMPTY_STRING', |
| 81 | * 'NULL_TO_STRING', 'ERR_NONE', 'FETCH_ORI_NEXT', |
| 82 | * 'FETCH_ORI_PRIOR', 'FETCH_ORI_FIRST', 'FETCH_ORI_LAST', |
| 83 | * 'FETCH_ORI_ABS', 'FETCH_ORI_REL', 'CURSOR_FWDONLY', 'CURSOR_SCROLL', |
| 84 | * 'ERR_CANT_MAP', 'ERR_SYNTAX', 'ERR_CONSTRAINT', 'ERR_NOT_FOUND', |
| 85 | * 'ERR_ALREADY_EXISTS', 'ERR_NOT_IMPLEMENTED', 'ERR_MISMATCH', |
| 86 | * 'ERR_TRUNCATED', 'ERR_DISCONNECTED', 'ERR_NO_PERM', |
| 87 | * ); |
| 88 | * |
| 89 | * $const = array(); |
| 90 | * foreach ($list as $name) { |
| 91 | * $const[$name] = constant("PDO::$name"); |
| 92 | * } |
| 93 | * var_export($const); |
| 94 | */ |
| 95 | const ATTR_AUTOCOMMIT = 0; |
| 96 | const ATTR_CASE = 8; |
| 97 | const ATTR_CLIENT_VERSION = 5; |
| 98 | const ATTR_CONNECTION_STATUS = 7; |
| 99 | const ATTR_CURSOR = 10; |
| 100 | const ATTR_CURSOR_NAME = 9; |
| 101 | const ATTR_DRIVER_NAME = 16; |
| 102 | const ATTR_ERRMODE = 3; |
| 103 | const ATTR_FETCH_CATALOG_NAMES = 15; |
| 104 | const ATTR_FETCH_TABLE_NAMES = 14; |
| 105 | const ATTR_MAX_COLUMN_LEN = 18; |
| 106 | const ATTR_ORACLE_NULLS = 11; |
| 107 | const ATTR_PERSISTENT = 12; |
| 108 | const ATTR_PREFETCH = 1; |
| 109 | const ATTR_SERVER_INFO = 6; |
| 110 | const ATTR_SERVER_VERSION = 4; |
| 111 | const ATTR_STATEMENT_CLASS = 13; |
| 112 | const ATTR_STRINGIFY_FETCHES = 17; |
| 113 | const ATTR_TIMEOUT = 2; |
| 114 | const CASE_LOWER = 2; |
| 115 | const CASE_NATURAL = 0; |
| 116 | const CASE_UPPER = 1; |
| 117 | const CURSOR_FWDONLY = 0; |
| 118 | const CURSOR_SCROLL = 1; |
| 119 | const ERR_ALREADY_EXISTS = NULL; |
| 120 | const ERR_CANT_MAP = NULL; |
| 121 | const ERR_CONSTRAINT = NULL; |
| 122 | const ERR_DISCONNECTED = NULL; |
| 123 | const ERR_MISMATCH = NULL; |
| 124 | const ERR_NO_PERM = NULL; |
| 125 | const ERR_NONE = '00000'; |
| 126 | const ERR_NOT_FOUND = NULL; |
| 127 | const ERR_NOT_IMPLEMENTED = NULL; |
| 128 | const ERR_SYNTAX = NULL; |
| 129 | const ERR_TRUNCATED = NULL; |
| 130 | const ERRMODE_EXCEPTION = 2; |
| 131 | const ERRMODE_SILENT = 0; |
| 132 | const ERRMODE_WARNING = 1; |
| 133 | const FETCH_ASSOC = 2; |
| 134 | const FETCH_BOTH = 4; |
| 135 | const FETCH_BOUND = 6; |
| 136 | const FETCH_CLASS = 8; |
| 137 | const FETCH_CLASSTYPE = 262144; |
| 138 | const FETCH_COLUMN = 7; |
| 139 | const FETCH_FUNC = 10; |
| 140 | const FETCH_GROUP = 65536; |
| 141 | const FETCH_INTO = 9; |
| 142 | const FETCH_LAZY = 1; |
| 143 | const FETCH_NAMED = 11; |
| 144 | const FETCH_NUM = 3; |
| 145 | const FETCH_OBJ = 5; |
| 146 | const FETCH_ORI_ABS = 4; |
| 147 | const FETCH_ORI_FIRST = 2; |
| 148 | const FETCH_ORI_LAST = 3; |
| 149 | const FETCH_ORI_NEXT = 0; |
| 150 | const FETCH_ORI_PRIOR = 1; |
| 151 | const FETCH_ORI_REL = 5; |
| 152 | const FETCH_SERIALIZE = 524288; |
| 153 | const FETCH_UNIQUE = 196608; |
| 154 | const NULL_EMPTY_STRING = 1; |
| 155 | const NULL_NATURAL = 0; |
| 156 | const NULL_TO_STRING = NULL; |
| 157 | const PARAM_BOOL = 5; |
| 158 | const PARAM_INPUT_OUTPUT = -2147483648; |
| 159 | const PARAM_INT = 1; |
| 160 | const PARAM_LOB = 3; |
| 161 | const PARAM_NULL = 0; |
| 162 | const PARAM_STMT = 4; |
| 163 | const PARAM_STR = 2; |
| 164 | /** |
| 165 | * Factory for Zend_Db_Adapter_Abstract classes. |
| 166 | * |
| 167 | * First argument may be a string containing the base of the adapter class |
| 168 | * name, e.g. 'Mysqli' corresponds to class Zend_Db_Adapter_Mysqli. This |
| 169 | * name is currently case-insensitive, but is not ideal to rely on this behavior. |
| 170 | * If your class is named 'My_Company_Pdo_Mysql', where 'My_Company' is the namespace |
| 171 | * and 'Pdo_Mysql' is the adapter name, it is best to use the name exactly as it |
| 172 | * is defined in the class. This will ensure proper use of the factory API. |
| 173 | * |
| 174 | * First argument may alternatively be an object of type Zend_Config. |
| 175 | * The adapter class base name is read from the 'adapter' property. |
| 176 | * The adapter config parameters are read from the 'params' property. |
| 177 | * |
| 178 | * Second argument is optional and may be an associative array of key-value |
| 179 | * pairs. This is used as the argument to the adapter constructor. |
| 180 | * |
| 181 | * If the first argument is of type Zend_Config, it is assumed to contain |
| 182 | * all parameters, and the second argument is ignored. |
| 183 | * |
| 184 | * @param mixed $adapter String name of base adapter class, or Zend_Config object. |
| 185 | * @param mixed $config OPTIONAL; an array or Zend_Config object with adapter parameters. |
| 186 | * @return Zend_Db_Adapter_Abstract |
| 187 | * @throws Zend_Db_Exception |
| 188 | */ |
| 189 | public static function factory($adapter, $config = array()) |
| 190 | { |
| 191 | if ($config instanceof \Zend_Config) { |
| 192 | $config = $config->toArray(); |
| 193 | } |
| 194 | /* |
| 195 | * Convert Zend_Config argument to plain string |
| 196 | * adapter name and separate config object. |
| 197 | */ |
| 198 | if ($adapter instanceof \Zend_Config) { |
| 199 | if (isset($adapter->params)) { |
| 200 | $config = $adapter->params->toArray(); |
| 201 | } |
| 202 | if (isset($adapter->adapter)) { |
| 203 | $adapter = (string) $adapter->adapter; |
| 204 | } else { |
| 205 | $adapter = null; |
| 206 | } |
| 207 | } |
| 208 | /* |
| 209 | * Verify that adapter parameters are in an array. |
| 210 | */ |
| 211 | if (!\is_array($config)) { |
| 212 | /** |
| 213 | * @see Zend_Db_Exception |
| 214 | */ |
| 215 | // require_once 'Zend/Db/Exception.php'; |
| 216 | throw new \Zend_Db_Exception('Adapter parameters must be in an array or a Zend_Config object'); |
| 217 | } |
| 218 | /* |
| 219 | * Verify that an adapter name has been specified. |
| 220 | */ |
| 221 | if (!\is_string($adapter) || empty($adapter)) { |
| 222 | /** |
| 223 | * @see Zend_Db_Exception |
| 224 | */ |
| 225 | // require_once 'Zend/Db/Exception.php'; |
| 226 | throw new \Zend_Db_Exception('Adapter name must be specified in a string'); |
| 227 | } |
| 228 | /* |
| 229 | * Form full adapter class name |
| 230 | */ |
| 231 | $adapterNamespace = 'Zend_Db_Adapter'; |
| 232 | if (isset($config['adapterNamespace'])) { |
| 233 | if ($config['adapterNamespace'] != '') { |
| 234 | $adapterNamespace = $config['adapterNamespace']; |
| 235 | } |
| 236 | unset($config['adapterNamespace']); |
| 237 | } |
| 238 | // Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606 |
| 239 | $adapterName = $adapterNamespace . '_'; |
| 240 | $adapterName .= \str_replace(' ', '_', \ucwords(\str_replace('_', ' ', \strtolower($adapter)))); |
| 241 | /* |
| 242 | * Load the adapter class. This throws an exception |
| 243 | * if the specified class cannot be loaded. |
| 244 | */ |
| 245 | if (!\class_exists($adapterName)) { |
| 246 | // require_once 'Zend/Loader.php'; |
| 247 | \Zend_Loader::loadClass($adapterName); |
| 248 | } |
| 249 | /* |
| 250 | * Create an instance of the adapter class. |
| 251 | * Pass the config to the adapter class constructor. |
| 252 | */ |
| 253 | $dbAdapter = new $adapterName($config); |
| 254 | /* |
| 255 | * Verify that the object created is a descendent of the abstract adapter type. |
| 256 | */ |
| 257 | if (!$dbAdapter instanceof \Zend_Db_Adapter_Abstract) { |
| 258 | /** |
| 259 | * @see Zend_Db_Exception |
| 260 | */ |
| 261 | // require_once 'Zend/Db/Exception.php'; |
| 262 | throw new \Zend_Db_Exception("Adapter class '{$adapterName}' does not extend Zend_Db_Adapter_Abstract"); |
| 263 | } |
| 264 | return $dbAdapter; |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 |