예제 #1
0
 public function getDb($returnEngine = false)
 {
     return Database::getDatabase($this->_modelDBName, $returnEngine);
 }
예제 #2
0
 public function execute($checkBindNumber = true)
 {
     if (Application::getDebug()) {
         Benchmark::getInstance($this->_configName)->startTime()->startRam();
     }
     if (is_null($this->_query) || !$this->_statement) {
         throw new \Exception('Prepare query before execute');
     }
     if ($checkBindNumber) {
         if (count($this->_params) < $this->_paramsNumberNecesary) {
             throw new \Exception('Miss bind parameters');
         }
     }
     // Bind parameters
     $i = 0;
     foreach ($this->_params as $param) {
         $bindName = $this->_bindParamType === Database::PARAM_BIND_POSITIONAL ? $i + 1 : ':' . $this->_namedParamOrder[$i];
         if ($param['isParam']) {
             $this->_statement->bindParam($bindName, $param['value'], $param['type']);
         } else {
             $this->_statement->bindValue($bindName, $param['value'], $param['type']);
         }
         $i++;
     }
     // Execute
     $this->_execute = $this->_statement->execute();
     //check error
     $lastError = $this->getLastError(true);
     if (!is_null($lastError)) {
         Logger::getInstance()->error('Sql query : ' . $this->_query . ' has error : ' . $lastError);
     }
     // Debug
     if (Application::getDebug()) {
         Database::getDatabase($this->_configName)->logQuery($this->_query, $this->_params, $this->_bindParamType, $lastError);
     }
     return $this->_execute;
 }