예제 #1
0
 /**
  * Logs this statement
  * 
  * Sometimes you will need to debug specific statements. This method will create a logentry with the SQL query, the arguments used
  * and try to combine it for easy copy+paste from log to your sql tool (for retry).
  * @return void
  */
 public function LogDebug()
 {
     log_debug("SQL: " . $this->_sql_used . "\nARGS: ", $this->_arguments_used, "\nMerged: ", ResultSet::MergeSql($this->_ds, $this->_sql_used, $this->_arguments_used));
 }
예제 #2
0
 function __execute($injected_sql = false, $injected_arguments = array(), $ctor_args = null)
 {
     $sql = $injected_sql ? $injected_sql : $this->__toString();
     if ($injected_arguments) {
         if (is_array($injected_arguments)) {
             $this->_values = $injected_arguments;
         } else {
             $this->_values = array($injected_arguments);
         }
     }
     $this->_statement = $this->_ds->Prepare($sql);
     foreach ($this->_values as $i => $v) {
         if (is_integer($v)) {
             $this->_statement->bindValue($i + 1, $v, PDO::PARAM_INT);
         } elseif ($v instanceof DateTime) {
             $this->_statement->bindValue($i + 1, $v->format("c"));
         } else {
             $this->_statement->bindValue($i + 1, $v);
         }
     }
     if (!$this->_statement->execute()) {
         WdfDbException::Raise($this->_statement->ErrorOutput(), "\nArguments:", $this->_values, "\nMerged:", ResultSet::MergeSql($this->_ds, $sql, $this->_values));
     }
     $res = $this->_statement->fetchAll(PDO::FETCH_CLASS, get_class($this->_object), $ctor_args);
     return $res;
 }
예제 #3
0
 /**
  * Executes a statement and caches the result.
  * 
  * Of course returns the cached result if called again and cached result is still alive.
  * @param string $sql SQL statement
  * @param array $prms Arguments for the query
  * @param int $lifetime Lifetime in seconds
  * @return ResultSet The ResultSet
  */
 function CacheExecuteSql($sql, $prms = array(), $lifetime = 300)
 {
     if (!system_is_module_loaded('globalcache')) {
         return $this->ExecuteSql($sql, $prms);
     }
     $key = 'DB_Cache_Sql_' . md5($sql . serialize($prms));
     $null = null;
     if (is_null($res = cache_get($key, $null, true, false))) {
         $res = $this->ExecuteSql($sql, $prms);
         if ($res) {
             $res->fetchAll();
             $data = $res->serialize();
             cache_set($key, $data, $lifetime, true, false);
         }
     } else {
         $res = ResultSet::unserialize($res);
     }
     return $res;
 }