Esempio n. 1
0
 /**
  * Create instance of PDOStatement using provided SQL query and set of parameters.
  *
  * @todo more exceptions to be thrown
  * @param string $query
  * @param array  $parameters Parameters to be binded into query.
  * @return \PDOStatement
  * @throws QueryException
  */
 public function statement($query, array $parameters = [])
 {
     try {
         if ($this->isProfiling()) {
             $queryString = QueryInterpolator::interpolate($query, $parameters);
             $benchmark = $this->benchmark($this->name, $queryString);
         }
         /**
          * This code requires minor improvements to support prepared statements on user level.
          */
         //Prepared statement
         $pdoStatement = $this->prepare($query);
         foreach ($this->flattenParameters($parameters) as $index => $parameter) {
             //Let's mount statement parameters
             $pdoStatement->bindValue($index + 1, $parameter->getValue(), $parameter->getType());
         }
         try {
             $pdoStatement->execute();
         } finally {
             if (!empty($benchmark)) {
                 $this->benchmark($benchmark);
             }
         }
         //Only exists if profiling on
         if (!empty($queryString)) {
             $this->logger()->info($queryString, compact('query', 'parameters'));
         }
     } catch (\PDOException $exception) {
         if (empty($queryString)) {
             $queryString = QueryInterpolator::interpolate($query, $parameters);
         }
         $this->logger()->error($queryString, compact('query', 'parameters'));
         //Converting exception into query or integrity exception
         throw $this->clarifyException($exception);
     }
     return $pdoStatement;
 }
Esempio n. 2
0
 /**
  * Query string associated with PDOStatement. To be used for debug purposes only.
  *
  * @return string
  */
 public function queryString()
 {
     return QueryInterpolator::interpolate($this->statement->queryString, $this->parameters);
 }
Esempio n. 3
0
 /**
  * Get interpolated (populated with parameters) SQL which will be run against database, please
  * use this method for debugging purposes only.
  *
  * @return string
  */
 public function queryString()
 {
     return QueryInterpolator::interpolate($this->sqlStatement(), $this->getParameters());
 }