Beispiel #1
0
 /**
  * Prepare
  *
  * @param string $sql
  * @return Statement
  */
 public function prepare($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     $statement = $this->driver->createStatement($sql);
     return $statement;
 }
Beispiel #2
0
 /**
  * Execute
  *
  * @param  null|array|Parameters $parameters
  * @throws Exception\RuntimeException
  * @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();
     }
     $return = $this->resource->execute();
     if ($return === false) {
         if (in_array($this->resource->errno, array(1060, 1061, 1062))) {
             throw new Exception\DuplicateException($this->resource->error, $this->resource->errno);
         }
         throw new Exception\RuntimeException($this->resource->error);
     }
     if ($this->bufferResults === true) {
         $this->resource->store_result();
         $this->isPrepared = false;
         $buffered = true;
     } else {
         $buffered = false;
     }
     $result = $this->driver->createResult($this->resource, $buffered);
     return $result;
 }