Ejemplo n.º 1
0
 /**
  * @param null|array|Parameters $parameters
  * @throws Exception\InvalidQueryException
  * @return Result
  */
 public function execute($parameters = null)
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     if (!$this->parameters instanceof Parameters) {
         if ($parameters instanceof Parameters) {
             $this->parameters = $parameters;
             $parameters = null;
         } else {
             $this->parameters = new Parameters();
         }
     }
     if (is_array($parameters)) {
         $this->parameters->setFromArray($parameters);
     }
     if ($this->parameters->count() > 0) {
         $this->bindParameters();
     }
     try {
         $this->resource->execute();
     } catch (\PDOException $e) {
         $code = $e->errorInfo[1];
         $message = $e->errorInfo[2] ?: $e->getMessage();
         if (in_array($code, array(1060, 1061, 1062))) {
             throw new Exception\DuplicateException($message, $code, $e);
         }
         throw new Exception\InvalidQueryException($message, $code, $e);
     }
     $result = $this->driver->createResult($this->resource, $this);
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Prepare
  *
  * @param string $sql
  * @return Statement
  */
 public function prepare($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     $statement = $this->driver->createStatement($sql);
     return $statement;
 }