protected function _initDoctrine() { // autoload Doctrine Models Zend_Loader_Autoloader::getInstance()->registerNamespace('Doctrine')->pushAutoloader(array('Doctrine', 'autoload'), 'Doctrine'); // get the database connection parameters $db_params = $this->getPluginResource('db')->getParams(); // initialize the doctrine connection manager $manager = Doctrine_Manager::getInstance(); # set conservative loading for models, saves memory and does not include all model files $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); # set validation for all fields $manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL); # allow overidding of field accessors $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); // configure and set the cache driver on the manager $cacheConn = Doctrine_Manager::connection(new PDO('sqlite::memory:')); $cacheDriver = new Doctrine_Cache_Db(array('connection' => $cacheConn, 'tableName' => 'cache')); // create the cache table $cacheDriver->createTable(); // set the cache for the queries and resultsets $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver); $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver); $manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 86400); $dsn = 'mysql://' . $db_params['username'] . ':' . $db_params['password'] . '@' . $db_params['host'] . '/' . $db_params['dbname']; $conn = $manager->connection($dsn); // set all field names to be escaped with the MySQL backtick. This allows the use of MySQL keywords as column names $conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true); # use the native enumeration for the database $conn->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true); }
public function testTest() { $cacheConn = Doctrine_Manager::getInstance()->openConnection('sqlite::memory:', 'cache', false); $cacheDriver = new Doctrine_Cache_Db(array('tableName' => 'cache', 'connection' => $cacheConn)); $cacheDriver->createTable(); $currentCacheDriver = $this->conn->getAttribute(Doctrine_Core::ATTR_QUERY_CACHE); $this->conn->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver); try { $q = Doctrine_Query::create()->from('Ticket_1630_BlogPost p')->leftJoin('p.Translation t INDEXBY t.lang'); $results = $q->execute(); $results = $q->execute(); $this->pass(); } catch (Exception $e) { $this->fail(); } $this->conn->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $currentCacheDriver); }
RingsideApiConfig::$upload_rootUrl = $uploadRootUrl; } ### Setup your doctrine connection require_once 'Doctrine/lib/Doctrine.php'; spl_autoload_register(array('Doctrine', 'autoload')); //Doctrine::loadModels('ringside/api/dao/records/'); $dsn = "{$db_type}://{$db_username}:{$db_password}@{$db_server}/{$db_name}"; $manager = Doctrine_Manager::getInstance(); // Set up validation FIXME: this really breaks out stuff, not good //$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL); // Set up caching if (isset($useDbCache) && $useDbCache === true) { $sqlite_conn = Doctrine_Manager::connection(new PDO('sqlite:memory')); $cacheDriver = new Doctrine_Cache_Db(array('connection' => $sqlite_conn, 'tableName' => 'ringside_api')); try { $cacheDriver->createTable(); } catch (Doctrine_Connection_Exception $e) { if ($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) { $cacheDriver = null; } } if (null !== $cacheDriver) { $manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver); $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver); // Result cache set for 5 minutes - FIXME: this causes php to crash. Riddle me that! //$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 300); //Doctrine::ATTR_RESULT_CACHE_LIFESPAN; //Doctrine::ATTR_QUERY_CACHE_LIFESPAN } } $conn = Doctrine_Manager::connection($dsn);