예제 #1
0
파일: Sqlite.php 프로젝트: finzaiko/Panada
 /**
  * Establish a new connection to SQLite server.
  */
 private function establishConnection()
 {
     try {
         if (!($this->link = new \SQLite3($this->config['database'], SQLITE3_OPEN_READWRITE))) {
             throw new RunException('Unable connect to database in <strong>' . $this->connection . '</strong> connection.');
         }
     } catch (RunException $e) {
         RunException::outputError($e->getMessage());
     }
 }
예제 #2
0
파일: Mysql.php 프로젝트: finzaiko/Panada
 /**
  * Select the databse.
  */
 private function selectDb($dbname)
 {
     if (is_null($this->link)) {
         $this->init();
     }
     try {
         if (!@mysql_select_db($dbname, $this->link)) {
             throw new RunException('Unable to select database in <strong>' . $this->connection . '</strong> connection.');
         }
     } catch (RunException $e) {
         RunException::outputError($e->getMessage());
     }
 }
예제 #3
0
 /**
  * Inital for all process
  *
  * @return void
  */
 private function init()
 {
     if (is_null($this->link)) {
         $this->link = $this->establishConnection();
     }
     try {
         if (!$this->link) {
             throw new RunException('Unable connect to database in <strong>' . $this->connection . '</strong> connection.');
         }
     } catch (RunException $e) {
         RunException::outputError($e->getMessage());
     }
 }
예제 #4
0
 public function __construct($config, $connectionName)
 {
     /**
      * Makesure Mongo extension is enabled
      */
     if (!class_exists('Mongo')) {
         throw new RunException('Mongo PECL extension that required by Mongodb Driver is not available.');
     }
     $this->config = $config;
     $this->connection = $connectionName;
     /**
      * $this->config['options'] is the mongodb connection option. Eg: array('replicaSet' => true, 'connect' => false)
      */
     try {
         parent::__construct($this->config['host'], $this->config['options']);
     } catch (\MongoConnectionException $e) {
         RunException::outputError('Unable connect to database in <strong>' . $connectionName . '</strong> connection.');
     }
 }
예제 #5
0
파일: Redis.php 프로젝트: ferdhika31/males
 public function __construct($config)
 {
     if (!extension_loaded('redis')) {
         die('Redis extension that required by Driver Redis is not available.');
     }
     parent::__construct();
     foreach ($config['server'] as $server) {
         if ($server['persistent']) {
             $this->pconnect($server['host'], $server['port'], $server['timeout']);
         } else {
             $this->connect($server['host'], $server['port'], $server['timeout']);
         }
     }
     try {
         $this->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
     } catch (\RedisException $e) {
         Resources\RunException::outputError($e->getMessage());
     }
 }
예제 #6
0
 /**
  * Print the error
  *
  * @return string
  */
 protected function printError()
 {
     if ($caller = \Resources\RunException::getErrorCaller(5)) {
         $error_str = sprintf('Database error %1$s for query %2$s made by %3$s', $this->lastError, $this->lastQuery, $caller);
     } else {
         $error_str = sprintf('Database error %1$s for query %2$s', $this->lastError, $this->lastQuery);
     }
     \Resources\RunException::outputError($error_str);
 }