/** * Contructor initializes the object * * @access public * @param ConnectionSetting $csetting * @param Observable $listener * @param IDataDriver (optional) if not provided, then DataAdapter will attempt to instantiate one based on ConnectionSetting->Type */ function __construct($csetting, $listener = null, IDataDriver $driver = null) { $this->_driver = $driver; if ($this->_driver == null) { // the driver was not explicitly provided so we will try to create one from // the connection setting based on the database types that we do know about switch ($csetting->Type) { case "mysql": include_once "verysimple/DB/DataDriver/MySQL.php"; $this->_driver = new DataDriverMySQL(); break; case "sqlite": include_once "verysimple/DB/DataDriver/SQLite.php"; $this->_driver = new DataDriverSQLite(); break; default: include_once "verysimple/DB/DataDriver/" . $csetting->Type . ".php"; $classname = "DataDriver" . $csetting->Type; $this->_driver = new $classname(); break; } } DataAdapter::$DRIVER_INSTANCE = $this->_driver; $this->AttachObserver($listener); $this->_csetting =& $csetting; $this->Observe("DataAdapter Instantiated", OBSERVE_DEBUG); }
/** * Load the data driver * @throws Exception */ public function LoadDriver() { if ($this->_driver == null) { require_once "verysimple/IO/Includer.php"; // the driver was not explicitly provided so we will try to create one from // the connection setting based on the database types that we do know about switch ($this->ConnectionSetting->Type) { case "mysql": include_once "verysimple/DB/DataDriver/MySQL.php"; $this->_driver = new DataDriverMySQL(); break; case "mysqli": include_once "verysimple/DB/DataDriver/MySQLi.php"; $this->_driver = new DataDriverMySQLi(); break; case "sqlite": include_once "verysimple/DB/DataDriver/SQLite.php"; $this->_driver = new DataDriverSQLite(); break; default: try { Includer::IncludeFile("verysimple/DB/DataDriver/" . $this->ConnectionSetting->Type . ".php"); $classname = "DataDriver" . $this->ConnectionSetting->Type; $this->_driver = new $classname(); } catch (IncludeException $ex) { throw new Exception('Unknown DataDriver "' . $this->ConnectionSetting->Type . '" specified in connection settings'); } break; } DataAdapter::$DRIVER_INSTANCE = $this->_driver; } }