Redaxscript\Db::init PHP Method

init() public static method

init the class
Since: 2.6.0
public static init ( )
    public static function init()
    {
        $dbType = self::$_config->get('dbType');
        $dbHost = self::$_config->get('dbHost');
        $dbName = self::$_config->get('dbName');
        $dbUser = self::$_config->get('dbUser');
        $dbPassword = self::$_config->get('dbPassword');
        $dbSocket = strstr($dbHost, '.sock');
        /* mysql and pgsql */
        if ($dbType === 'mysql' || $dbType === 'pgsql') {
            if ($dbType === 'mysql') {
                self::configure('connection_string', 'mysql:' . ($dbSocket ? 'unix_socket' : 'host') . '=' . $dbHost . ';dbname=' . $dbName . ';charset=utf8');
            } else {
                self::configure('connection_string', 'pgsql:' . ($dbSocket ? 'unix_socket' : 'host') . '=' . $dbHost . ';dbname=' . $dbName . ';options=--client_encoding=utf8');
            }
            /* username and password */
            self::configure('username', $dbUser);
            if ($dbPassword) {
                self::configure('password', $dbPassword);
            }
        }
        /* sqlite */
        if ($dbType === 'sqlite') {
            self::configure('sqlite:' . $dbHost);
        }
        /* general */
        self::configure(['caching' => true, 'caching_auto_clear' => true, 'return_result_sets' => true]);
    }

Usage Example

コード例 #1
0
ファイル: DbTest.php プロジェクト: ITw3/redaxscript
 /**
  * testInit
  *
  * @since 2.2.0
  */
 public function testInit()
 {
     /* setup */
     Db::init($this->_config);
     /* result */
     $result = Db::getDb();
     /* compare */
     $this->assertInstanceOf('PDO', $result);
 }
All Usage Examples Of Redaxscript\Db::init