/** * @param mixed $parameters * @throws Exception\InvalidQueryException * @return Result */ public function execute($parameters = null) { if (!$this->isPrepared) { $this->prepare(); } /** START Standard ParameterContainer Merging Block */ if (!$this->parameterContainer instanceof ParameterContainer) { if ($parameters instanceof ParameterContainer) { $this->parameterContainer = $parameters; $parameters = null; } else { $this->parameterContainer = new ParameterContainer(); } } if (is_array($parameters)) { $this->parameterContainer->setFromArray($parameters); } if ($this->parameterContainer->count() > 0) { $this->bindParametersFromContainer(); } /** END Standard ParameterContainer Merging Block */ try { $this->resource->execute(); } catch (\PDOException $e) { throw new Exception\InvalidQueryException('Statement could not be executed', null, $e); } $result = $this->driver->createResult($this->resource, $this); return $result; }
/** * @param $sql * @return Result * @throws \Zend\Db\Adapter\Exception\InvalidQueryException */ public function execute($sql) { if (!$this->isConnected()) { $this->connect(); } $resultResource = $this->resource->query($sql); if ($resultResource === false) { $errorInfo = $this->resource->errorInfo(); throw new Exception\InvalidQueryException($errorInfo[2]); } $result = $this->driver->createResult($resultResource, $sql); return $result; }
/** * @todo Should this use the ability of PDOStatement to return objects of a specified class? * @param mixed $parameters * @return Result */ public function execute($parameters = null) { if (!$this->isPrepared) { $this->prepare(); } $parameters = $parameters ?: ($parameters = $this->parameterContainer); if ($parameters != null) { if (is_array($parameters)) { $parameters = new ParameterContainer($parameters); } if (!$parameters instanceof ParameterContainerInterface) { throw new \InvalidArgumentException('ParameterContainer expected'); } $this->bindParametersFromContainer($parameters); } if ($this->resource->execute() === false) { throw new Exception\InvalidQueryException($this->resource->error); } $result = $this->driver->createResult($this->resource); return $result; }