コード例 #1
0
ファイル: database.class.php プロジェクト: jvirtism/AnEngine
 /**
  * Get database connection
  *
  * Get the database connection, using parameters from the settings file to
  * connect. The optional second argument may be an instance of {@link
  * AeInterface_File} or a path to configuration file, which will be opened
  * using {@link AeSettings}. If it is ommited, a database.ini file is
  * assumed, which should reside in the current working directory (see {@link
  * http://php.net/getcwd getcwd()} function) or anywhere else inside the
  * include path (see {@link http://php.net/get_include_path
  * get_include_path() function}.
  *
  * @throws AeDatabaseException #500 if connection fails due to bad
  *                             configuration
  *
  * @param string                      $name     name of the connection
  * @param string|AeInterface_Settings $settings custom configuration file
  *
  * @return AeInterface_Database instance of a database driver
  */
 public static function getConnection($name = null, $settings = null)
 {
     $name = $name !== null ? $name : self::DEFAULT_CONNECTION;
     if (!$settings instanceof AeInterface_Settings) {
         if ($settings === null || !file_exists($settings)) {
             $file = getcwd() . SLASH . 'database.ini';
             if (!file_exists($file)) {
                 $file = 'database.ini';
             }
         } else {
             $file = $settings;
         }
         $settings = AeSettings::getInstance($file);
     }
     $driver = $settings->get($name . '.driver', self::DEFAULT_DRIVER);
     $username = $settings->get($name . '.user', 'root');
     $password = $settings->get($name . '.password', '');
     $options = $settings->get($name . '.options', array());
     $connection = self::getInstance($driver, $username, $password, $options);
     return $connection;
 }
コード例 #2
0
ファイル: session.class.php プロジェクト: jvirtism/AnEngine
 /**
  * Get session connection
  *
  * Reads session configuration from the specified configuration file and
  * creates the appropriate session. Created session is started automatically
  *
  * @param string $name                          name of the connection
  * @param string $settings|AeInterface_Settings custom configuration file
  *
  * @return AeSession
  */
 public static function getConnection($name = null, $settings = null)
 {
     $name = $name !== null ? $name : self::DEFAULT_CONNECTION;
     if (!$settings instanceof AeInterface_Settings) {
         if ($settings === null || !file_exists($settings)) {
             $file = getcwd() . SLASH . 'session.ini';
             if (!file_exists($file)) {
                 $file = 'session.ini';
             }
         } else {
             $file = $settings;
         }
         $settings = AeSettings::getInstance($file);
     }
     $driver = $settings->get($name . '.driver', null);
     $options = $settings->get($name . '.options', null);
     try {
         $connection = self::getInstance($driver, $options);
         $connection->start();
     } catch (AeSessionException $e) {
         // *** Driver exception while connecting
         switch ($e->getCode()) {
             case '400':
                 throw new AeSessionException(ucfirst($name) . ' connection load failed: bad configuration', 500);
                 break;
             default:
                 throw $e;
                 break;
         }
         // *** Exception while loading driver
         throw $e;
     }
     return $connection;
 }