예제 #1
0
파일: Result.php 프로젝트: ZhuJingfa/HuiLib
 /**
  * 获取所有
  * @param string $fetchStyle
  * @throws \HuiLib\Error\Exception
  * @return array|object
  */
 public function fetchAll()
 {
     if ($this->innerStatment == NULL) {
         throw new \HuiLib\Error\Exception('fetchAll必须先调用Query::query');
     }
     return $this->innerStatment->fetchAll($this->fetchStyle);
 }
예제 #2
0
 /**
  * Fetches all of the rows returned by the query.
  *
  * @return array
  */
 protected function rows()
 {
     if ($this->rows === null) {
         $this->rows = $this->pdoStatement->fetchAll(PDO::FETCH_ASSOC);
     }
     return $this->rows;
 }
 /**
  * <b>Não é passado com os Joins</b>
  * 
  * @return array[Objetos]
  */
 public function findAll()
 {
     $sql = "SELECT * FROM {$this->Table}";
     $this->Stmt = Conn::prepare($sql);
     $this->Stmt->execute();
     return $this->Stmt->fetchAll();
 }
예제 #4
0
파일: Database.php 프로젝트: sclib/database
 /**
  * @param string $dbObjectName
  *
  * @return array
  */
 public function fetchAll($dbObjectName = '')
 {
     if ('' === $dbObjectName) {
         $dbObjectName = $this->_objectName;
     }
     return $this->_statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $dbObjectName);
 }
예제 #5
0
 /**
  * @param string $entity [null]
  * @return array $entities
  */
 public function fetchEntities($entity = null)
 {
     $entity = $entity ?: $this->entity;
     if (is_null($entity)) {
         $entity = 'stdClass';
     }
     return $this->statement->fetchAll(\PDO::FETCH_CLASS, $entity);
 }
예제 #6
0
 function fetchAll(PDOStatement $result, $result_type = Database::FETCH_ASSOC, $className = "stdClass", $classArgs = null)
 {
     if ($result_type == self::FETCH_CLASS) {
         $rows = $result->fetchAll($result_type, $className, $classArgs);
     } else {
         $rows = $result->fetchAll($result_type);
     }
     return $rows;
 }
예제 #7
0
 /**
  * @param \PDOStatement $statement
  * @param MObject|null $parent
  */
 public function __construct(\PDOStatement $statement, MObject $parent = null)
 {
     parent::__construct($parent);
     $this->statement = $statement;
     $this->rows = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
     $this->fields = empty($this->rows) ? array() : array_keys((array) $this->rows[0]);
     $this->rowCount = count($this->rows);
     $this->columnCount = count($this->fields);
 }
예제 #8
0
파일: Statement.php 프로젝트: shiwolang/db
 public function all($param = null, $args = [])
 {
     if (is_callable($param)) {
         return $this->statement->fetchAll(\PDO::FETCH_FUNC, $param);
     }
     if ($param !== null && is_string($param)) {
         $this->bindToClass($param, $args);
     }
     return $this->statement->fetchAll();
 }
예제 #9
0
 /**
  * Fetch all results
  * 
  * @param boolean|string $object Fetch as object
  * @return \stdClass[]
  */
 public function all($object = TRUE)
 {
     if ($object) {
         if ($object === TRUE) {
             return $this->stmt->fetchAll(\PDO::FETCH_OBJ);
         }
         return $this->stmt->fetchAll(\PDO::FETCH_CLASS, $object);
     }
     return $this->stmt->fetchAll(\PDO::FETCH_ASSOC);
 }
예제 #10
0
 private function Execute()
 {
     $this->Connect();
     try {
         $this->getSyntax();
         $this->read->execute();
         $this->result = $this->read->fetchAll();
     } catch (PDOException $e) {
         echo "<b>Erro ao ler:</b> {$e->getMessage()}";
     }
 }
예제 #11
0
파일: PdoLoader.php 프로젝트: brick/brick
 /**
  * {@inheritdoc}
  */
 public function load($locale)
 {
     $parameters = array_merge([$locale], $this->parameters);
     $this->statement->execute($parameters);
     $rows = $this->statement->fetchAll(\PDO::FETCH_NUM);
     $result = [];
     foreach ($rows as $row) {
         $result[$row[0]] = $row[1];
     }
     return $result;
 }
예제 #12
0
파일: Read.php 프로젝트: jairophp/amarmais
 private function Execute()
 {
     $this->Connect();
     try {
         $this->getSyntax();
         $this->Read->execute();
         $this->Result = $this->Read->fetchAll();
     } catch (PDOException $e) {
         $this->Result = null;
         WSErro("<b>Erro ao Ler:</b> {$e->getMessage()}", $e->getCode());
     }
 }
예제 #13
0
 public function fetch()
 {
     $this->executeQuery();
     if ($this->fetchResults === null) {
         $this->fetchResults = $this->statement->fetchAll(PDO::FETCH_ASSOC);
         $this->statement->closeCursor();
     }
     if (array_key_exists($this->currentFetchIndex, $this->fetchResults) && $this->fetchResults[$this->currentFetchIndex] !== null) {
         return $this->fetchResults[$this->currentFetchIndex++];
     }
     return false;
 }
예제 #14
0
 private function Execute()
 {
     $this->getCon();
     try {
         $this->setParameters();
         $this->read->execute();
         $this->result = $this->read->fetchAll();
     } catch (PDOException $ex) {
         $this->result = false;
         $erro = 'algo errado...' . $ex->getMessage();
     }
 }
예제 #15
0
파일: Iterator.php 프로젝트: hayate/hayate
 public function __construct(PDOStatement $stm, $model = null, $fetchMode = PDO::FETCH_OBJ)
 {
     $this->offset = 0;
     if (is_string($model)) {
         $this->rows = $stm->fetchAll(PDO::FETCH_ASSOC);
         $this->model = strtolower(str_ireplace('_model', '', $model));
     } else {
         $this->rows = $stm->fetchAll($fetchMode);
         $this->model = null;
     }
     $this->rowCount = count($this->rows);
 }
예제 #16
0
 public function fetch($fetchStyle = null, $all = true)
 {
     if (is_null($this->query)) {
         throw new \Exception('Cannot invoke fetch. Try using query or prepare/execute before fetch.');
     }
     if (is_null($fetchStyle)) {
         $fetchStyle = \PDO::FETCH_OBJ;
     }
     if ($all === true) {
         return $this->query->fetchAll($fetchStyle);
     }
     return $this->query->fetch($fetchStyle);
 }
예제 #17
0
파일: PdoReader.php 프로젝트: lmkhang/mcntw
 /**
  * Load data if it hasn't been loaded yet
  */
 protected function loadData()
 {
     if (null === $this->data) {
         $this->statement->execute();
         $this->data = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
     }
 }
예제 #18
0
파일: FetchData.php 프로젝트: mejt/Krauza
 public static function executeFetchAllStatement(\PDOStatement $stmt)
 {
     if (!$stmt->execute()) {
         return [];
     }
     return $stmt->fetchAll(\PDO::FETCH_ASSOC);
 }
예제 #19
0
 /**
  * Returns the data result of the statement
  * @return array
  */
 public function getData()
 {
     if ($this->data === null) {
         $this->data = $this->statement->fetchAll($this->fetchMode);
     }
     return $this->data;
 }
예제 #20
0
 public function all($class = null)
 {
     if (!$this->result) {
         throw new Exception('Can\'t fetch results if no query!');
     }
     return $class === false ? $this->result->fetchAll(PDO::FETCH_ASSOC) : $this->result->fetchAll(PDO::FETCH_CLASS, $class ?: self::config('fetch'));
 }
예제 #21
0
파일: Pdo.php 프로젝트: echoOly/php_base
 /**
  * 获取全部记录
  * 由于该方法会造成安全问题,所以不建议使用。在必须使用的场合,需要程序人员对sql语句做严格验证
  * @param string $sql 预处理执行的sql
  * @param array $data 符合pdo预处理模式键值对
  * @return array
  * @deprecated since version 108
  */
 public function fetchAll($sql, $data = null)
 {
     $this->execute($sql, $data);
     $data = $this->stmt instanceof \PDOStatement ? $this->stmt->fetchAll() : FALSE;
     $this->stmt = null;
     return $data;
 }
예제 #22
0
파일: Statement.php 프로젝트: shen2/mypdo
 protected function _fetchAll()
 {
     switch ($this->_fetchMode) {
         case self::FETCH_DATAOBJECT:
             self::$_stmt->setFetchMode(PDO::FETCH_ASSOC);
             $rowset = new \SplFixedArray(self::$_stmt->rowCount());
             $rowClass = $this->_fetchArgument;
             foreach (self::$_stmt as $index => $data) {
                 $rowset[$index] = new $rowClass($data, true, $this->_ctorArgs);
             }
             return $rowset;
         case self::FETCH_CLASSFUNC:
             self::$_stmt->setFetchMode(PDO::FETCH_ASSOC);
             $rowset = new \SplFixedArray(self::$_stmt->rowCount());
             $classFunc = $this->_fetchArgument;
             foreach (self::$_stmt as $index => $data) {
                 $rowClass = $classFunc($data);
                 $rowset[$index] = new $rowClass($data, true, $this->_ctorArgs);
             }
             return $rowset;
         default:
             if (isset($this->_ctorArgs)) {
                 return self::$_stmt->fetchAll($this->_fetchMode, $this->_fetchArgument, $this->_ctorArgs);
             }
             if (isset($this->_fetchArgument)) {
                 return self::$_stmt->fetchAll($this->_fetchMode, $this->_fetchArgument);
             }
             if (isset($this->_fetchMode)) {
                 return self::$_stmt->fetchAll($this->_fetchMode);
             }
     }
 }
예제 #23
0
 /**
  * Вернет все строки результата как массив объектов указанного класса.
  * Если класс не указан - объекты будут \StdClass
  *
  * @param string $className
  *
  * @return array
  */
 public function fetchClass($className = null)
 {
     if ($className === null) {
         $className = '\\StdClass';
     }
     return $this->stmt->fetchAll(\PDO::FETCH_CLASS, $className);
 }
예제 #24
0
파일: DB.php 프로젝트: sysulsj/phpwebsite
 /**
  * Fetches all rows based on the current pdo_statement and returns them.
  * @return array
  */
 public function fetchAll()
 {
     $this->checkStatement();
     $result = $this->pdo_statement->fetchAll(\PDO::FETCH_ASSOC);
     $this->clearStatement();
     return $result;
 }
예제 #25
0
 /**
  * 根据prepare类函数中的参数个数,传入$params
  * @param array $params 如array(':Avalue'=>'10', ':Bvalue'=>'yellow');
  * @param string $fetchRows 默认All时获取所有的,One则只获取一条
  * @param string $fetchType 默认array获得字段索引数组,row获得以数字为索引数组,both获得array和row,obj获得一个对象,col获取列则必须传入colIndex,如果$fetchRows和$fetchType都为空,则返回PDOStatement对象
  * @return \PDOStatement “注意此对象可能会被修改,所以不要写类似保存后在另外的地方使用的方法”
  */
 public function selectPrepared($params = array(), $fetchRows = 'All', $fetchType = 'array', $colIndex = 0)
 {
     $result = $this->execute($params);
     if ($result) {
         if ($fetchType == 'row') {
             $fetched = \PDO::FETCH_NUM;
         } elseif ($fetchType == 'obj') {
             $fetched = \PDO::FETCH_FETCH_CLASS;
         } elseif ($fetchType == '') {
             $fetched = \PDO::FETCH_BOTH;
         } elseif ($fetchType == 'col') {
             $fetched = \PDO::FETCH_COLUMN;
         } else {
             $fetched = \PDO::FETCH_ASSOC;
         }
         if ($fetchRows == 'All' || $fetchRows == 'all') {
             if ($fetchType == 'col') {
                 return $this->pdoStatement->fetchAll($fetched, $colIndex);
             } else {
                 return $this->pdoStatement->fetchAll($fetched);
             }
         } elseif ($fetchRows == 'One' || $fetchRows == 'one') {
             if ($fetchType == 'col') {
                 return $this->pdoStatement->fetch($fetched, $colIndex);
             } else {
                 return $this->pdoStatement->fetch($fetched);
             }
         }
         return $this->pdoStatement;
     } else {
         return FALSE;
     }
 }
예제 #26
0
 /**
  * Returns an array containing all of the result set rows.
  *
  * @param string $fetch_style
  *            Controls how the rows will be returned.
  * @return mixed
  */
 public function fetchAll($fetch_style = null)
 {
     $this->setFetchMode($fetch_style);
     $rows = $this->statement->fetchAll();
     $this->statement->closeCursor();
     return $rows;
 }
 /**
  * @param $entityClass
  * @return array
  */
 public function getResultList($entityClass)
 {
     $this->sqlStatement->execute($this->params);
     if ($this->sqlStatement->rowCount() > 0) {
         $entities = array();
         $rows = $this->sqlStatement->fetchAll();
         foreach ($rows as $row) {
             /** @var Entity $entity */
             $entity = new $entityClass($this);
             $entity->init($row);
             array_push($entities, $entity);
         }
         return $entities;
     }
     return array();
 }
예제 #28
0
 public function fetchAll()
 {
     if (!$this->_sth) {
         throw new \Exception();
     }
     return $this->_sth->fetchAll(\PDO::FETCH_ASSOC);
 }
예제 #29
0
 /**
  * @method execute
  * @param $query|string
  * @return DataBase
  */
 public function execute($query)
 {
     $this->error = false;
     if ($query) {
         if ($this->query = $this->pdo->prepare($this->escapeDoubleSpaces($query))) {
             if (count($this->paramArray)) {
                 foreach ($this->paramArray as $param => $val) {
                     if (is_null($val)) {
                         $var = PDO::PARAM_NULL;
                     } elseif (is_int($val)) {
                         $var = PDO::PARAM_INT;
                     } elseif (is_bool($val)) {
                         $var = PDO::PARAM_BOOL;
                     } else {
                         $var = PDO::PARAM_STR;
                         if ($this->queryType === self::QUERY_TYPE_UPDATE) {
                             $val = $this->wrapInSingleQuotes($val);
                         }
                     }
                     $this->query->bindValue($param, $val, $var);
                 }
                 #End Foreach
             }
             if ($this->query->execute()) {
                 $this->results = $this->query->fetchAll(PDO::FETCH_OBJ);
                 $this->count = $this->query->rowCount();
             } else {
                 $this->error = true;
             }
         }
     }
     $this->reset();
     return $this;
 }
예제 #30
0
 public function select(\PDOStatement $stmnt, array $params = array(), $fetchStyle = null, $fetchArgument = null, array $ctorArgs = array())
 {
     $fetchStyle = $fetchStyle !== null ? $fetchStyle : self::$defaultFetchStyle;
     try {
         $this->triggerListeners('beforeSelect', array($this, $stmnt, $params));
         $stmnt->execute($params);
         $this->triggerListeners('afterSelect', array($this, $stmnt, $params));
         if ($fetchStyle !== \PDO::FETCH_CLASS && $fetchStyle !== self::FETCH_FUNC) {
             return $stmnt->fetchAll($fetchStyle);
         } else {
             return $stmnt->fetchAll($fetchStyle, $fetchArgument);
         }
     } catch (\PDOException $e) {
         throw new DBException($e, $stmnt->queryString, $params);
     }
 }