PageRenderTime 193ms CodeModel.GetById 19ms RepoModel.GetById 3ms app.codeStats 1ms

/src/application/libraries/Zend/Db.php

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