00001 <?php
00002
00032 class Zend_Db
00033 {
00034
00038 const PROFILER = 'profiler';
00039
00043 const CASE_FOLDING = 'caseFolding';
00044
00048 const AUTO_QUOTE_IDENTIFIERS = 'autoQuoteIdentifiers';
00049
00053 const ALLOW_SERIALIZATION = 'allowSerialization';
00054
00058 const AUTO_RECONNECT_ON_UNSERIALIZE = 'autoReconnectOnUnserialize';
00059
00063 const INT_TYPE = 0;
00064 const BIGINT_TYPE = 1;
00065 const FLOAT_TYPE = 2;
00066
00099 const ATTR_AUTOCOMMIT = 0;
00100 const ATTR_CASE = 8;
00101 const ATTR_CLIENT_VERSION = 5;
00102 const ATTR_CONNECTION_STATUS = 7;
00103 const ATTR_CURSOR = 10;
00104 const ATTR_CURSOR_NAME = 9;
00105 const ATTR_DRIVER_NAME = 16;
00106 const ATTR_ERRMODE = 3;
00107 const ATTR_FETCH_CATALOG_NAMES = 15;
00108 const ATTR_FETCH_TABLE_NAMES = 14;
00109 const ATTR_MAX_COLUMN_LEN = 18;
00110 const ATTR_ORACLE_NULLS = 11;
00111 const ATTR_PERSISTENT = 12;
00112 const ATTR_PREFETCH = 1;
00113 const ATTR_SERVER_INFO = 6;
00114 const ATTR_SERVER_VERSION = 4;
00115 const ATTR_STATEMENT_CLASS = 13;
00116 const ATTR_STRINGIFY_FETCHES = 17;
00117 const ATTR_TIMEOUT = 2;
00118 const CASE_LOWER = 2;
00119 const CASE_NATURAL = 0;
00120 const CASE_UPPER = 1;
00121 const CURSOR_FWDONLY = 0;
00122 const CURSOR_SCROLL = 1;
00123 const ERR_ALREADY_EXISTS = NULL;
00124 const ERR_CANT_MAP = NULL;
00125 const ERR_CONSTRAINT = NULL;
00126 const ERR_DISCONNECTED = NULL;
00127 const ERR_MISMATCH = NULL;
00128 const ERR_NO_PERM = NULL;
00129 const ERR_NONE = '00000';
00130 const ERR_NOT_FOUND = NULL;
00131 const ERR_NOT_IMPLEMENTED = NULL;
00132 const ERR_SYNTAX = NULL;
00133 const ERR_TRUNCATED = NULL;
00134 const ERRMODE_EXCEPTION = 2;
00135 const ERRMODE_SILENT = 0;
00136 const ERRMODE_WARNING = 1;
00137 const FETCH_ASSOC = 2;
00138 const FETCH_BOTH = 4;
00139 const FETCH_BOUND = 6;
00140 const FETCH_CLASS = 8;
00141 const FETCH_CLASSTYPE = 262144;
00142 const FETCH_COLUMN = 7;
00143 const FETCH_FUNC = 10;
00144 const FETCH_GROUP = 65536;
00145 const FETCH_INTO = 9;
00146 const FETCH_LAZY = 1;
00147 const FETCH_NAMED = 11;
00148 const FETCH_NUM = 3;
00149 const FETCH_OBJ = 5;
00150 const FETCH_ORI_ABS = 4;
00151 const FETCH_ORI_FIRST = 2;
00152 const FETCH_ORI_LAST = 3;
00153 const FETCH_ORI_NEXT = 0;
00154 const FETCH_ORI_PRIOR = 1;
00155 const FETCH_ORI_REL = 5;
00156 const FETCH_SERIALIZE = 524288;
00157 const FETCH_UNIQUE = 196608;
00158 const NULL_EMPTY_STRING = 1;
00159 const NULL_NATURAL = 0;
00160 const NULL_TO_STRING = NULL;
00161 const PARAM_BOOL = 5;
00162 const PARAM_INPUT_OUTPUT = -2147483648;
00163 const PARAM_INT = 1;
00164 const PARAM_LOB = 3;
00165 const PARAM_NULL = 0;
00166 const PARAM_STMT = 4;
00167 const PARAM_STR = 2;
00168
00194 public static function factory($adapter, $config = array())
00195 {
00196 if ($config instanceof Zend_Config) {
00197 $config = $config->toArray();
00198 }
00199
00200
00201
00202
00203
00204 if ($adapter instanceof Zend_Config) {
00205 if (isset($adapter->params)) {
00206 $config = $adapter->params->toArray();
00207 }
00208 if (isset($adapter->adapter)) {
00209 $adapter = (string) $adapter->adapter;
00210 } else {
00211 $adapter = null;
00212 }
00213 }
00214
00215
00216
00217
00218 if (!is_array($config)) {
00222 require_once 'Zend/Db/Exception.php';
00223 throw new Zend_Db_Exception('Adapter parameters must be in an array or a Zend_Config object');
00224 }
00225
00226
00227
00228
00229 if (!is_string($adapter) || empty($adapter)) {
00233 require_once 'Zend/Db/Exception.php';
00234 throw new Zend_Db_Exception('Adapter name must be specified in a string');
00235 }
00236
00237
00238
00239
00240 $adapterNamespace = 'Zend_Db_Adapter';
00241 if (isset($config['adapterNamespace'])) {
00242 if ($config['adapterNamespace'] != '') {
00243 $adapterNamespace = $config['adapterNamespace'];
00244 }
00245 unset($config['adapterNamespace']);
00246 }
00247
00248
00249 $adapterName = $adapterNamespace . '_';
00250 $adapterName .= str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapter))));
00251
00252
00253
00254
00255
00256 if (!class_exists($adapterName)) {
00257 require_once 'Zend/Loader.php';
00258 Zend_Loader::loadClass($adapterName);
00259 }
00260
00261
00262
00263
00264
00265 $dbAdapter = new $adapterName($config);
00266
00267
00268
00269
00270 if (! $dbAdapter instanceof Zend_Db_Adapter_Abstract) {
00274 require_once 'Zend/Db/Exception.php';
00275 throw new Zend_Db_Exception("Adapter class '$adapterName' does not extend Zend_Db_Adapter_Abstract");
00276 }
00277
00278 return $dbAdapter;
00279 }
00280
00281 }