Пример #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);
 }
Пример #2
0
 /**
  *   Sends the sql to the database and returns the results.
  *
  *   @internal Switches between ADOConnection::Execute() and
  *    ADOConnection::SelectLimit() depending on the $query parameter's
  *    $solutionModifier "limit" and "offset" settings.
  *   Uses $query variable.
  *
  *   @param array $arSql     Array that gets a SQL query string once imploded
  *
  *   @return mixed           Anything ADOConnection::Execute() may return
  *   @throws Exception       If Database query does not work
  */
 function queryDb($arSql, $nOffset, $nLimit)
 {
     $strSql = SparqlEngineDb_SqlMerger::getSelect($this->query, $arSql);
     if ($strSql == '()') {
         return new ADORecordSet(false);
     }
     // I want associative arrays.
     $oldmode = $this->dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
     if (isset($GLOBALS['debugSparql']) && $GLOBALS['debugSparql']) {
         echo 'SQL query: ' . $strSql . "\n";
     }
     if ($nLimit === null && $nOffset == 0) {
         $ret = $this->dbConn->execute($strSql);
     } else {
         if ($nLimit === null) {
             $ret = $this->dbConn->SelectLimit($strSql, -1, $nOffset);
         } else {
             $ret = $this->dbConn->SelectLimit($strSql, $nLimit, $nOffset);
         }
     }
     //... but others maybe not
     $this->dbConn->SetFetchMode($oldmode);
     if (!$ret) {
         //Error occured
         throw new Exception('ADOdb error: ' . $this->dbConn->ErrorMsg() . "\n" . $strSql);
     }
     return $ret;
 }
Пример #3
0
 /**
  * Constructor
  *
  * @param ADOConnection $db An instance of ADOConnection.
  *
  * @throws XML_Query2XML_DBException If the ADOConnection instance passed as
  *                          argument was not connected to the database server.
  */
 public function __construct(ADOConnection $db)
 {
     if (!$db->IsConnected()) {
         throw new XML_Query2XML_DBException('ADOConnection instance was not connected');
     }
     $db->SetFetchMode(ADODB_FETCH_ASSOC);
     $this->_db = $db;
 }
 /**
  * Метод получения коннекта к БД
  * 
  * @return ADOConnection
  */
 protected final function getConnection()
 {
     if ($this->CONNECTION != null) {
         return $this->CONNECTION;
         //---
     }
     if (!$this->isConfigured()) {
         PsUtil::raise('Cannot get DB connection, {} is not configured.', get_called_class());
     }
     $this->LOGGER->info();
     $this->LOGGER->info('?  Connection for [{}] is requested', $this->CONNECTION_PARAMS);
     $URL = $this->CONNECTION_PARAMS->url();
     //Посмотрим, есть ли у нас нужный коннект
     if (array_key_exists($URL, $this->CONNECTIONS)) {
         $this->LOGGER->info('<  Fast returned from cache');
         return $this->CONNECTION = $this->CONNECTIONS[$URL];
     }
     //Отлогируем
     $this->LOGGER->info('+  Establishing connection {}', $this->CONNECTION_PARAMS);
     //Подключаем adodb
     PsLibs::inst()->AdoDb();
     //Подключаемся
     $this->CONNECTION = ADONewConnection($URL);
     if (!is_object($this->CONNECTION)) {
         PsUtil::raise("Unable to connect to [{}]", $this->CONNECTION_PARAMS);
     }
     //Зададим некоторые настройки
     $this->CONNECTION->debug = ADODB_DEBUG;
     $this->CONNECTION->SetFetchMode(ADODB_FETCH_ASSOC);
     $this->CONNECTION->query("SET NAMES 'utf8'");
     $this->CONNECTION->query("SET CHARACTER SET 'utf8'");
     //Положим соединение в пул
     if (array_key_exists($URL, $this->CONNECTIONS)) {
         raise_error('Double trying to register db connection');
     }
     $this->LOGGER->info('<  Established connection returned');
     return $this->CONNECTIONS[$URL] = $this->CONNECTION;
 }