Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Db.php
Go to the documentation of this file.
1 <?php
2 
32 class Zend_Db
33 {
34 
38  const PROFILER = 'profiler';
39 
43  const CASE_FOLDING = 'caseFolding';
44 
48  const FETCH_MODE = 'fetchMode';
49 
53  const AUTO_QUOTE_IDENTIFIERS = 'autoQuoteIdentifiers';
54 
58  const ALLOW_SERIALIZATION = 'allowSerialization';
59 
63  const AUTO_RECONNECT_ON_UNSERIALIZE = 'autoReconnectOnUnserialize';
64 
68  const INT_TYPE = 0;
69  const BIGINT_TYPE = 1;
70  const FLOAT_TYPE = 2;
71 
104  const ATTR_AUTOCOMMIT = 0;
105  const ATTR_CASE = 8;
108  const ATTR_CURSOR = 10;
109  const ATTR_CURSOR_NAME = 9;
110  const ATTR_DRIVER_NAME = 16;
111  const ATTR_ERRMODE = 3;
115  const ATTR_ORACLE_NULLS = 11;
116  const ATTR_PERSISTENT = 12;
117  const ATTR_PREFETCH = 1;
118  const ATTR_SERVER_INFO = 6;
122  const ATTR_TIMEOUT = 2;
123  const CASE_LOWER = 2;
124  const CASE_NATURAL = 0;
125  const CASE_UPPER = 1;
126  const CURSOR_FWDONLY = 0;
127  const CURSOR_SCROLL = 1;
128  const ERR_ALREADY_EXISTS = NULL;
129  const ERR_CANT_MAP = NULL;
130  const ERR_CONSTRAINT = NULL;
131  const ERR_DISCONNECTED = NULL;
132  const ERR_MISMATCH = NULL;
133  const ERR_NO_PERM = NULL;
134  const ERR_NONE = '00000';
135  const ERR_NOT_FOUND = NULL;
136  const ERR_NOT_IMPLEMENTED = NULL;
137  const ERR_SYNTAX = NULL;
138  const ERR_TRUNCATED = NULL;
139  const ERRMODE_EXCEPTION = 2;
140  const ERRMODE_SILENT = 0;
141  const ERRMODE_WARNING = 1;
142  const FETCH_ASSOC = 2;
143  const FETCH_BOTH = 4;
144  const FETCH_BOUND = 6;
145  const FETCH_CLASS = 8;
146  const FETCH_CLASSTYPE = 262144;
147  const FETCH_COLUMN = 7;
148  const FETCH_FUNC = 10;
149  const FETCH_GROUP = 65536;
150  const FETCH_INTO = 9;
151  const FETCH_LAZY = 1;
152  const FETCH_NAMED = 11;
153  const FETCH_NUM = 3;
154  const FETCH_OBJ = 5;
155  const FETCH_ORI_ABS = 4;
156  const FETCH_ORI_FIRST = 2;
157  const FETCH_ORI_LAST = 3;
158  const FETCH_ORI_NEXT = 0;
159  const FETCH_ORI_PRIOR = 1;
160  const FETCH_ORI_REL = 5;
161  const FETCH_SERIALIZE = 524288;
162  const FETCH_UNIQUE = 196608;
163  const NULL_EMPTY_STRING = 1;
164  const NULL_NATURAL = 0;
165  const NULL_TO_STRING = NULL;
166  const PARAM_BOOL = 5;
167  const PARAM_INPUT_OUTPUT = -2147483648;
168  const PARAM_INT = 1;
169  const PARAM_LOB = 3;
170  const PARAM_NULL = 0;
171  const PARAM_STMT = 4;
172  const PARAM_STR = 2;
173 
199  public static function factory($adapter, $config = array())
200  {
201  if ($config instanceof Zend_Config) {
202  $config = $config->toArray();
203  }
204 
205  /*
206  * Convert Zend_Config argument to plain string
207  * adapter name and separate config object.
208  */
209  if ($adapter instanceof Zend_Config) {
210  if (isset($adapter->params)) {
211  $config = $adapter->params->toArray();
212  }
213  if (isset($adapter->adapter)) {
214  $adapter = (string) $adapter->adapter;
215  } else {
216  $adapter = null;
217  }
218  }
219 
220  /*
221  * Verify that adapter parameters are in an array.
222  */
223  if (!is_array($config)) {
227  #require_once 'Zend/Db/Exception.php';
228  throw new Zend_Db_Exception('Adapter parameters must be in an array or a Zend_Config object');
229  }
230 
231  /*
232  * Verify that an adapter name has been specified.
233  */
234  if (!is_string($adapter) || empty($adapter)) {
238  #require_once 'Zend/Db/Exception.php';
239  throw new Zend_Db_Exception('Adapter name must be specified in a string');
240  }
241 
242  /*
243  * Form full adapter class name
244  */
245  $adapterNamespace = 'Zend_Db_Adapter';
246  if (isset($config['adapterNamespace'])) {
247  if ($config['adapterNamespace'] != '') {
248  $adapterNamespace = $config['adapterNamespace'];
249  }
250  unset($config['adapterNamespace']);
251  }
252 
253  // Adapter no longer normalized- see http://framework.zend.com/issues/browse/ZF-5606
254  $adapterName = $adapterNamespace . '_';
255  $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapter))));
256 
257  /*
258  * Load the adapter class. This throws an exception
259  * if the specified class cannot be loaded.
260  */
261  if (!class_exists($adapterName)) {
262  #require_once 'Zend/Loader.php';
263  Zend_Loader::loadClass($adapterName);
264  }
265 
266  /*
267  * Create an instance of the adapter class.
268  * Pass the config to the adapter class constructor.
269  */
270  $dbAdapter = new $adapterName($config);
271 
272  /*
273  * Verify that the object created is a descendent of the abstract adapter type.
274  */
275  if (! $dbAdapter instanceof Zend_Db_Adapter_Abstract) {
279  #require_once 'Zend/Db/Exception.php';
280  throw new Zend_Db_Exception("Adapter class '$adapterName' does not extend Zend_Db_Adapter_Abstract");
281  }
282 
283  return $dbAdapter;
284  }
285 
286 }
const PROFILER
Definition: Db.php:38
const ERR_NONE
Definition: Db.php:134
const ATTR_PREFETCH
Definition: Db.php:117
const ERRMODE_WARNING
Definition: Db.php:141
const FETCH_ORI_PRIOR
Definition: Db.php:159
const FETCH_ORI_REL
Definition: Db.php:160
const ATTR_STRINGIFY_FETCHES
Definition: Db.php:121
const FETCH_ORI_NEXT
Definition: Db.php:158
const ERR_MISMATCH
Definition: Db.php:132
const ERR_DISCONNECTED
Definition: Db.php:131
const ERR_CONSTRAINT
Definition: Db.php:130
const FETCH_LAZY
Definition: Db.php:151
const ERR_ALREADY_EXISTS
Definition: Db.php:128
static loadClass($class, $dirs=null)
Definition: Loader.php:52
const ATTR_CURSOR_NAME
Definition: Db.php:109
const ERR_SYNTAX
Definition: Db.php:137
$config
Definition: fraud_order.php:17
const BIGINT_TYPE
Definition: Db.php:69
const ATTR_FETCH_TABLE_NAMES
Definition: Db.php:113
const INT_TYPE
Definition: Db.php:68
const AUTO_RECONNECT_ON_UNSERIALIZE
Definition: Db.php:63
const FETCH_SERIALIZE
Definition: Db.php:161
const ATTR_ERRMODE
Definition: Db.php:111
const PARAM_INT
Definition: Db.php:168
const FETCH_BOUND
Definition: Db.php:144
const ERRMODE_SILENT
Definition: Db.php:140
const FETCH_ASSOC
Definition: Db.php:142
const ERRMODE_EXCEPTION
Definition: Db.php:139
const CURSOR_FWDONLY
Definition: Db.php:126
const FETCH_COLUMN
Definition: Db.php:147
const FETCH_ORI_FIRST
Definition: Db.php:156
const ERR_CANT_MAP
Definition: Db.php:129
const FETCH_GROUP
Definition: Db.php:149
const ATTR_SERVER_INFO
Definition: Db.php:118
const FLOAT_TYPE
Definition: Db.php:70
const FETCH_NAMED
Definition: Db.php:152
const ERR_NOT_IMPLEMENTED
Definition: Db.php:136
$adapter
Definition: webapi_user.php:16
const ATTR_MAX_COLUMN_LEN
Definition: Db.php:114
const ERR_NOT_FOUND
Definition: Db.php:135
const ATTR_AUTOCOMMIT
Definition: Db.php:104
const ERR_TRUNCATED
Definition: Db.php:138
const FETCH_BOTH
Definition: Db.php:143
const ATTR_FETCH_CATALOG_NAMES
Definition: Db.php:112
const ATTR_TIMEOUT
Definition: Db.php:122
const ATTR_ORACLE_NULLS
Definition: Db.php:115
const FETCH_NUM
Definition: Db.php:153
const FETCH_MODE
Definition: Db.php:48
const NULL_EMPTY_STRING
Definition: Db.php:163
const CURSOR_SCROLL
Definition: Db.php:127
const PARAM_STMT
Definition: Db.php:171
static factory($adapter, $config=array())
Definition: Db.php:199
const ATTR_CURSOR
Definition: Db.php:108
const PARAM_BOOL
Definition: Db.php:166
const FETCH_OBJ
Definition: Db.php:154
const ATTR_PERSISTENT
Definition: Db.php:116
const FETCH_CLASS
Definition: Db.php:145
const AUTO_QUOTE_IDENTIFIERS
Definition: Db.php:53
const ATTR_DRIVER_NAME
Definition: Db.php:110
const CASE_UPPER
Definition: Db.php:125
const ATTR_CASE
Definition: Db.php:105
const CASE_NATURAL
Definition: Db.php:124
const PARAM_NULL
Definition: Db.php:170
const PARAM_INPUT_OUTPUT
Definition: Db.php:167
const PARAM_LOB
Definition: Db.php:169
const FETCH_ORI_ABS
Definition: Db.php:155
const FETCH_ORI_LAST
Definition: Db.php:157
const FETCH_FUNC
Definition: Db.php:148
const ATTR_STATEMENT_CLASS
Definition: Db.php:120
const ATTR_CONNECTION_STATUS
Definition: Db.php:107
const ERR_NO_PERM
Definition: Db.php:133
const ALLOW_SERIALIZATION
Definition: Db.php:58
const ATTR_SERVER_VERSION
Definition: Db.php:119
const FETCH_INTO
Definition: Db.php:150
const ATTR_CLIENT_VERSION
Definition: Db.php:106
const CASE_FOLDING
Definition: Db.php:43
const FETCH_CLASSTYPE
Definition: Db.php:146
const NULL_NATURAL
Definition: Db.php:164
const CASE_LOWER
Definition: Db.php:123
const FETCH_UNIQUE
Definition: Db.php:162
const NULL_TO_STRING
Definition: Db.php:165
const PARAM_STR
Definition: Db.php:172