Пример #1
0
 function __construct($type, $host, $user, $pass, $db, $debug)
 {
     $this->_adoConnection = NewADOConnection($type);
     $this->_adoConnection->debug = $debug;
     $status = $this->_adoConnection->Connect($host, $user, $pass, $db);
     if (!$status) {
         throw new Exception("Không kết nối được CSDL");
     }
     $this->_adoConnection->SetCharSet('utf8');
     $this->_adoConnection->SetFetchMode(ADODB_FETCH_ASSOC);
 }
 /**
  * Create DB connection
  */
 protected function connect()
 {
     /** @var $this->connection \ADOConnection */
     $this->connection =& NewADOConnection($this->driver);
     $host = $this->host;
     if ($this->port) {
         $host .= ':' . $this->port;
     }
     // connect
     if ($this->db) {
         $this->connection->Connect($host, $this->user, $this->password, $this->db);
     } else {
         $this->connection->Connect($host, $this->user, $this->password);
     }
     // check connection
     if (!$this->connection->IsConnected()) {
         $errMsg = $this->connection->ErrorMsg();
         $this->utilityFuncs->throwException('db_connection_failed', $errMsg);
     }
     // execute initial statement
     if ($this->setDBinit) {
         $this->utilityFuncs->debugMessage('sql_request', [$this->setDBinit]);
         $this->connection->Execute($this->setDBinit);
         // error occured?
         if ($this->connection->ErrorNo() != 0) {
             $errMsg = $this->connection->ErrorMsg();
             $this->utilityFuncs->debugMessage('sql_request_error', [$errMsg], 3);
         }
     }
 }