Exemple #1
0
 /**
  * @param SelectInterface $select
  * @param string $mode
  * @param int|null $extraArg
  * @return array|string|false
  */
 public static function fetch(SelectInterface $select, $mode = "assoc", $extraArg = null)
 {
     $method = "fetch" . ucwords($mode);
     if ($extraArg === null) {
         return self::$conn->{$method}($select->getStatement(), $select->getBindValues());
     } else {
         return self::$conn->{$method}($select->getStatement(), $select->getBindValues(), $extraArg);
     }
 }
 public function fetchResult(SelectInterface $select)
 {
     $result = null;
     $stmt = $select->getStatement();
     try {
         $statement = $this->db->prepare($stmt);
         $statement->execute($select->getBindValues());
         $result = $statement->fetch();
     } catch (PDOException $e) {
         $this->logger->error($select->__toString());
         $this->logger->error($e->getMessage());
         return null;
     }
     return $result ?: null;
 }
Exemple #3
0
 /**
  * execute query
  *
  * @param \Aura\SqlQuery\AbstractQuery|\Aura\SqlQuery\Common\SelectInterface|\Aura\SqlQuery\Common\ValuesInterface $queryObject
  * @return array
  * @throws \Exception
  */
 public function query($queryObject)
 {
     $query = $queryObject->__toString();
     $sth = self::$_connection->prepare($query);
     if (!$sth) {
         $err = self::$_connection->errorInfo();
         throw new \Exception('DB Error: ' . $err[0] . ' - ' . $err[2]);
     }
     $values = $queryObject->getBindValues();
     foreach ($values as $key => $val) {
         $sth->bindParam(':' . $key, $val);
         unset($val);
     }
     $res = $sth->execute();
     if (!$res) {
         $err = $sth->errorInfo();
         throw new \Exception('DB Error: ' . $err[0] . ' - ' . $err[2]);
     }
     return $sth;
 }
 /**
  *
  * Formats a sub-SELECT statement, binding values from a Select object as
  * needed.
  *
  * @param string|SelectInterface $spec A sub-SELECT specification.
  *
  * @param string $indent Indent each line with this string.
  *
  * @return string The sub-SELECT string.
  *
  */
 protected function subSelect($spec, $indent)
 {
     if ($spec instanceof SelectInterface) {
         $this->bindValues($spec->getBindValues());
     }
     return PHP_EOL . $indent . ltrim(preg_replace('/^/m', $indent, (string) $spec)) . PHP_EOL;
 }