Example #1
0
File: One.php Project: schpill/thin
 /**
  * Internal helper method for executing statments. Logs queries, and
  * stores statement object in ::_last_statment, accessible publicly
  * through ::get_last_statement()
  * @param string $query
  * @param array $parameters An array of parameters to be bound in to the query
  * @param string $connection_name Which connection to use
  * @return bool Response of PDOStatement::execute()
  */
 protected static function _execute($query, $parameters = [], $connection_name = self::DEFAULT_CONNECTION)
 {
     $statement = self::get_db($connection_name)->prepare($query);
     self::$_lastStatement = $statement;
     $time = microtime(true);
     foreach ($parameters as $key => &$param) {
         if (is_null($param)) {
             $type = PDO::PARAM_NULL;
         } else {
             if (is_bool($param)) {
                 $type = PDO::PARAM_BOOL;
             } else {
                 if (is_int($param)) {
                     $type = PDO::PARAM_INT;
                 } else {
                     $type = PDO::PARAM_STR;
                 }
             }
         }
         $statement->bindParam(is_int($key) ? ++$key : $key, $param, $type);
     }
     $q = $statement->execute();
     self::_logQuery($query, $parameters, $connection_name, microtime(true) - $time);
     return $q;
 }