/**
  * Sets up the database connection.
  * @param $dsn The datasource name. See: <a href="http://nl3.php.net/manual/en/pdo.construct.php">http://nl3.php.net/manual/en/pdo.construct.php</a>
  * @code
  *   "sqlite:database.txt"
  *   "mysql:host=localhost;dbname=oodb"
  *   "pgsql:host=localhost;dbname=oodb"
  * @endcode
  * @param $username The database user's login username.
  * @param $password The database user's login password.
  */
 public static function setup($dsn, $username, $password)
 {
     assert('is_string($dsn) && $dsn != ""');
     assert('$username == null || is_string($username) && $username != ""');
     assert('$password == null || is_string($password)');
     assert('!self::isSetup()');
     try {
         ZurmoRedBean::setup($dsn, $username, $password);
         static::freeze();
         if (SHOW_QUERY_DATA) {
             Yii::app()->performance->setRedBeanQueryLogger(ZurmoRedBeanPluginQueryLogger::getInstanceAndAttach(ZurmoRedBean::$adapter));
         }
         if (defined('REDBEAN_DEBUG_TO_FILE') && REDBEAN_DEBUG_TO_FILE) {
             $queryLoggerComponent = Yii::createComponent(array('class' => 'application.core.models.ZurmoRedBeanQueryFileLogger'));
             $queryLoggerComponent->init();
             Yii::app()->setComponent('queryFileLogger', $queryLoggerComponent);
             ZurmoRedBean::debug(true, Yii::app()->queryFileLogger);
         } else {
             ZurmoRedBean::debug(defined('REDBEAN_DEBUG') && REDBEAN_DEBUG);
         }
         self::$isSetup = true;
         self::$databaseType = substr($dsn, 0, strpos($dsn, ':'));
     } catch (Exception $e) {
         self::close();
         throw $e;
     }
     assert('static::isSetup()');
     assert('RedBeanDatabase::isFrozen()');
 }
Beispiel #2
0
 /**
  * Sets up the database connection.
  * @param $dsn The datasource name. See: <a href="http://nl3.php.net/manual/en/pdo.construct.php">http://nl3.php.net/manual/en/pdo.construct.php</a>
  * @code
  *   "sqlite:database.txt"
  *   "mysql:host=localhost;dbname=oodb"
  *   "pgsql:host=localhost;dbname=oodb"
  * @endcode
  * @param $username The database user's login username.
  * @param $password The database user's login password.
  */
 public static function setup($dsn, $username, $password)
 {
     assert('is_string($dsn) && $dsn != ""');
     assert('$username == null || is_string($username) && $username != ""');
     assert('$password == null || is_string($password)');
     assert('!self::isSetup()');
     try {
         R::setup($dsn, $username, $password);
         R::$redbean->addEventListener("update", new RedBeanBeforeUpdateHintManager(R::$toolbox));
         if (SHOW_QUERY_DATA) {
             Yii::app()->performance->setRedBeanQueryLogger(ZurmoRedBeanPluginQueryLogger::getInstanceAndAttach(R::$adapter));
         }
         $debug = defined('REDBEAN_DEBUG') && REDBEAN_DEBUG;
         R::debug($debug);
         self::$isSetup = true;
         self::$databaseType = substr($dsn, 0, strpos($dsn, ':'));
     } catch (Exception $e) {
         self::close();
         throw $e;
     }
 }