Пример #1
0
 /**
  * 执行sql入口
  *
  * @param string $sql query to run
  * @param array $params the prepared query params
  * @return PDOStatement
  */
 public function query($sql, array $params = NULL, $cache_statement = FALSE)
 {
     $time = microtime(TRUE);
     self::$last_query = $sql;
     if (!$this->pdo) {
         $this->connect();
     }
     if ($cache_statement) {
         $hash = md5($sql);
         if (isset($this->statements[$hash])) {
             $statement = $this->statements[$hash];
         } else {
             $statement = $this->statements[$hash] = $this->pdo->prepare($sql);
         }
     } else {
         $statement = $this->pdo->prepare($sql);
     }
     $statement->execute($params);
     self::$queries[] = array(microtime(TRUE) - $time, $sql);
     return $statement;
 }
 /**
  * Run a SQL query and return the statement object
  *
  * @param string $sql query to run
  * @param array $params the prepared query params
  * @return PDOStatement
  */
 public function query($sql, array $params = NULL, $cache_statement = FALSE)
 {
     $time = microtime(TRUE);
     self::$last_query = $sql;
     // Connect if needed
     if (!$this->pdo) {
         $this->connect();
     }
     // Should we cached PDOStatements? (Best for batch inserts/updates)
     if ($cache_statement) {
         $hash = md5($sql);
         if (isset($this->statements[$hash])) {
             $statement = $this->statements[$hash];
         } else {
             $statement = $this->statements[$hash] = $this->pdo->prepare($sql);
         }
     } else {
         $statement = $this->pdo->prepare($sql);
     }
     $statement->execute($params);
     //$statement = $this->pdo->query($sql);
     // Save query results by database type
     self::$queries[$this->type][] = array(microtime(TRUE) - $time, $sql);
     return $statement;
 }