Exemple #1
0
 /**
  * Fetch next result
  * 
  * @param boolean|string $object Fetch as object
  * @return \stdClass
  */
 public function next($object = TRUE)
 {
     if ($object) {
         if ($object === TRUE) {
             return $this->stmt->fetchObject();
         }
         return $this->stmt->fetchObject($object);
     }
     return $this->stmt->fetch(\PDO::FETCH_ASSOC);
 }
Exemple #2
0
 public function fetch($class = null)
 {
     if (!$this->result) {
         throw new Exception('Can\'t fetch result if no query!');
     }
     return $class === false ? $this->result->fetch(PDO::FETCH_ASSOC) : $this->result->fetchObject($class ?: self::config('fetch'));
 }
Exemple #3
0
Fichier : Pdo.php Projet : orno/db
 /**
  * {@inheritdoc}
  *
  * @throws \Orno\Db\Exception\NoResourceException
  */
 public function fetchObject()
 {
     if (!$this->statement instanceof \PDOStatement) {
         throw new Exception\NoResourceException(sprintf('%s expects a query to have been prepared and executed', __METHOD__));
     }
     return $this->statement->fetchObject();
 }
 /**
  * @param \PDOStatement $statement
  *
  * @return \MongoId
  */
 protected function getMinimumValue(\PDOStatement $statement)
 {
     $result = $statement->fetchObject();
     if (!isset($result) || !isset($result->minimum)) {
         return;
     }
     return new \MongoId($result->minimum);
 }
 /**
  * 获得结果集中的下一行,同时根据设置的类返回如果没有设置则返回的使StdClass对象
  * 
  * @param string $className  使用的类
  * @param array $ctor_args   初始化参数
  * @return object
  */
 public function fetchObject($className = '', $ctor_args = array())
 {
     if ($className === '') {
         return $this->_statement->fetchObject();
     } else {
         return $this->_statement->fetchObject($className, $ctor_args);
     }
 }
 /** @param PDOStatement $query_result */
 private function treat_success($query_result)
 {
     $result_array = array();
     while ($query_obj = $query_result->fetchObject()) {
         $result_array[] = $query_obj;
     }
     parent::set_result('result_array', $result_array);
 }
Exemple #7
0
 protected static function fetch(\PDOStatement $result)
 {
     $out = array();
     while ($record = $result->fetchObject(get_called_class())) {
         $out[] = $record;
     }
     return $out;
 }
 /**
  * @param \PDOStatement $statement
  *
  * @return mixed $value
  */
 protected function getMinimumValue(\PDOStatement $statement)
 {
     $result = $statement->fetchObject();
     if (!isset($result) || !isset($result->minimum)) {
         return $this->defaultValue;
     }
     return $result->minimum;
 }
Exemple #9
0
 /**
  * Return the current rowset as an object with columns set as members of the object.
  *
  * @param string $className OPTIONAL: The class of the object returned,
  *                          defaults to 'stdClass'
  * @param array $args       OPTIONAL: Arguments to pass the the class constructor.
  * @return object
  */
 public function fetchObject($className = 'stdClass', $args = array())
 {
     try {
         return $this->_stmt->fetchObject($className, $args);
     } catch (PDOException $e) {
         throw new DBALite_Exception("Error fetching row from result set", $e);
     }
 }
Exemple #10
0
 function fetch(PDOStatement $result, $result_type = Database::FETCH_ASSOC, $className = "stdClass", $classArgs = null)
 {
     if ($result_type == self::FETCH_CLASS) {
         $row = $result->fetchObject($className, $classArgs);
     } else {
         $row = $result->fetch($result_type);
     }
     return $row;
 }
Exemple #11
0
 /**
  * Returns query result as an object based on the name of the called class.
  *
  * @param PDOStatement $q
  *
  * @return Model $object 
  */
 private static function asObject($q, $getFkAsObject)
 {
     while ($object = $q->fetchObject(get_called_class())) {
         if ($getFkAsObject) {
             self::getFkAsObject($object);
         }
         return $object;
     }
 }
Exemple #12
0
 /**
  * Fetches the next row and returns it as an object.
  *
  * @param string $class  OPTIONAL Name of the class to create.
  * @param array  $config OPTIONAL Constructor arguments for the class.
  * @return mixed One object instance of the specified class.
  * @throws Zend_Db_Statement_Exception
  */
 public function fetchObject($class = 'stdClass', array $config = array())
 {
     try {
         return $this->_stmt->fetchObject($class, $config);
     } catch (PDOException $e) {
         require_once 'Zend/Db/Statement/Exception.php';
         throw new Zend_Db_Statement_Exception($e->getMessage());
     }
 }
Exemple #13
0
 /**
  * Executes statement and returns result as DataObject
  *
  * @return DataObject
  */
 public function single()
 {
     $this->execute();
     $data = $this->stmt->fetchObject('\\Core\\Data\\DataObject');
     if (!empty($data)) {
         $data = $this->executeCallbackAndSchemeHandler($data);
     }
     return $data;
 }
Exemple #14
0
 /**
  * Returns information about a definition.
  *
  * @param string $term Term about which to return information
  *
  * @return void
  */
 public function onCommandLartinfo($term)
 {
     $this->select->execute(array(':name' => $term));
     $row = $this->select->fetchObject();
     $msg = $this->getEvent()->getNick() . ': ';
     if (!$row) {
         $msg .= 'Lart not found';
     } else {
         $msg .= 'Term: ' . $row->name . ', Definition: ' . $row->definition . ', User: '******', Added: ' . date('n/j/y g:i A', $row->tstamp);
     }
     $this->doNotice($this->getEvent()->getSource(), $msg);
 }
 /**
  * @param \PDOStatement $statement
  *
  * @return \MongoDate
  */
 protected function getMinimumValue(\PDOStatement $statement)
 {
     $result = $statement->fetchObject();
     if (!isset($result) || !isset($result->minimum)) {
         return new \MongoDate(strtotime($this->defaultValue));
     }
     if ($this->timezone) {
         $date = $result->minimum . ' ' . $this->timezone;
     } else {
         $date = $result->minimum;
     }
     return new \MongoDate(strtotime($date));
 }
 /**
  * @param \PDOStatement $statement
  *
  * @return \MongoDate
  */
 protected function getMinimumValue(\PDOStatement $statement)
 {
     $result = $statement->fetchObject();
     if (!isset($result) || !isset($result->minimum)) {
         $date = new \DateTime($this->defaultValue);
     } else {
         $date = new \DateTime($result->minimum);
     }
     if ($this->timezone) {
         $date->setTimezone(new \DateTimeZone($this->timezone));
     }
     return new \MongoDate($date->getTimestamp());
 }
 /**
  * @param PDOStatement $query_result
  */
 private function treat_success($query_result)
 {
     // Se o login e senha passado existem, inicia uma sessão, caso contrário, avisa o usuário.
     if ($result_obj = $query_result->fetchObject()) {
         // Define o nome no retorno
         parent::set_result('name', $result_obj->name);
         // Guarda o Id, para manter o login, e o Nome do usuário, para evitar uma consulta.
         TSession::set_value('id_user', $result_obj->id);
         TSession::set_value('name', $result_obj->name);
     } else {
         parent::set_error(1, "O par de usuário e senha não foi encontrado.");
     }
 }
Exemple #18
0
 /**
  * Return the correct object back.
  *
  * @param PDOStatement $Statement
  * @return mixed
  * @author Justin Palmer
  **/
 public static function factory(PDOStatement $Statement, $set = false)
 {
     $count = $Statement->rowCount();
     if ($set || $count > 1) {
         return new ResultSet($Statement);
     }
     switch ($count) {
         case 0:
             throw new RecordNotFoundException($Statement->queryString);
         case 1:
             return $Statement->fetchObject('ResultRow');
     }
 }
Exemple #19
0
 /**
  *
  * @see Iterator::rewind()
  */
 public function rewind()
 {
     //Dirty hack because rewind() is called before entering the loop
     //and on object creation we already have query executed
     if ($this->_needsRefresh) {
         $this->_refresh();
     } else {
         $this->_needsRefresh = true;
     }
     $this->_currentRowObj = $this->_statement->fetchObject('\\phpSweetPDO\\RecordsetRow');
     if ($this->_statement->errorCode() !== '00000') {
         throw new DbException($this->_statement->errorInfo(), $this->_statement->queryString);
     }
 }
Exemple #20
0
 /**
  * Get results
  * @return array
  */
 public function get_results()
 {
     if (!empty($this->fetched_rows)) {
         return $this->fetched_rows;
     }
     $this->fetched_rows = array();
     if (!empty($this->result) && $this->result->rowCount() > 0) {
         try {
             while ($row = $this->result->fetchObject()) {
                 $this->fetched_rows[] = $row;
             }
         } catch (Exception $e) {
         }
     }
     return $this->fetched_rows;
 }
Exemple #21
0
 /**
  * Fetches one row and returns it as an object of class $class_name. Some notes:
  * 1) The class constuctor WILL BE CALLED.
  * 2) If the variable is set in the constructor, it will overwrite whatever
  *    is pulled from the database.
  *
  * @param string $class_name Name of class to instantiate.
  * @param array $args Array of elements passed to constructor.
  * @return object
  */
 public function fetchObject($class_name, array $args = null)
 {
     $this->checkStatement();
     // PDO's fetchObject second parameter is type hinted so you can't
     // pass null to it without receiving a warning. This is why we have
     // to check and have a separate call.
     if (isset($args)) {
         $result = $this->pdo_statement->fetchObject($class_name, $args);
     } else {
         $result = $this->pdo_statement->fetchObject($class_name);
     }
     if (empty($result)) {
         $this->clearStatement();
     }
     return $result;
 }
Exemple #22
0
 /**
  * iterates over a result object and calls $callback for each row in the result
  * @param \PDOStatement|mixed $result result object with a fetchObject() method
  * @param callable $callback
  * @return array
  */
 protected function autoIterate($result, $callback)
 {
     $data = [];
     while ($row = $result->fetchObject()) {
         $callback($data, $row);
     }
     return $data;
 }
Exemple #23
0
 /**
  * Returns an array of object rows based on the last prepare/execute
  *
  * @param PDOStatement $sth
  * @param string $type the type of objects to be returned
  * @return array an array of object rows
  */
 public function getResultObjects(PDOStatement $sth, $class = 'stdClass')
 {
     $output = array();
     while (($o = $sth->fetchObject($class)) !== false) {
         array_push($output, $o);
     }
     return $output;
 }
Exemple #24
0
 public function fetchObject($class = 'StdClass', $options = NULL)
 {
     if ($this->dbh->cache && $this->cachedData) {
         $data = current($this->cachedData);
         next($this->cachedData);
         $obj = new $class();
         foreach ($data as $key => $val) {
             $obj->{$key} = $val;
         }
         if (method_exists($obj, '__wakeup')) {
             $obj->__wakeup();
         }
         return $obj;
     } else {
         return parent::fetchObject($class, $options);
     }
 }
Exemple #25
0
 /**
  * Overwrite. Fixes HHVM strict issue.
  */
 public function fetchObject($class_name = "stdClass", $ctor_args = null)
 {
     return parent::fetchObject($class_name, $ctor_args);
 }
 /**
  * 获取对象返回
  *
  * @access public
  * @param string $class_name 创建类名
  * @return object $object 数据对象
  */
 public function fetch_object($class_name = 'stdClass')
 {
     return parent::fetchObject($class_name);
 }
Exemple #27
0
 /**
  * Método criado para o agrupamento de valores de um tipo especifico, como algumas tabelas não possuem uma chave primária definida, não é possível usar o recurso do PDO que é semelhente ao desta função
  * @param PDOStatement $prepare O resultado de uma consulta
  * @param string|array $colunaChave O nome da coluna que servira de chave para o agrupamento
  * @return array Um array com os valores agrupados de acorod com a coluna informada
  */
 public function agruparPDOStatement(PDOStatement $prepare, $colunaChave)
 {
     if (!is_string($colunaChave)) {
         throw new Exception("Invalid value: a coluna informada é inválida");
     }
     $arrayRet = array();
     while ($row = $prepare->fetchObject()) {
         if (is_string($colunaChave)) {
             $arrayRet[$row->{$colunaChave}][] = $row;
         } elseif (is_array($colunaChave)) {
             foreach ($colunaChave as $chave) {
                 $arrayRet[$row->{$value}][] = $row;
             }
         } else {
             throw new Exception("Ivalid value: o nome da chave é inválido");
         }
     }
     return $arrayRet;
 }
Exemple #28
0
 /**
  * Returns the first row as an object
  * @param PDOStatement $ps
  * @param str $obj
  * @return array numbered keys, with Objects
  */
 protected final function getDataRowsAsObjects($ps, $obj)
 {
     $data = array();
     while ($row = $ps->fetchObject($obj)) {
         $data[] = $row;
     }
     $ps->closeCursor();
     return $data;
 }
Exemple #29
0
 /**
  * @param \PDOStatement $res
  * @param string $class
  * @return mixed
  */
 public static function fetch($res, $class = 'stdClass')
 {
     if ($class != null) {
         return $res->fetchObject($class);
     } else {
         return $res->fetch(\PDO::FETCH_ASSOC);
     }
 }
Exemple #30
0
 /**
  * Une methode fetch qui retourne un tableau d'objets de la classe courante
  * @param PDOStatement $s
  */
 public static function fetch(\PDOStatement $s)
 {
     $class = get_called_class();
     $lines = array();
     while ($line = $s->fetchObject($class)) {
         $lines[] = $line;
     }
     return $lines;
 }