当前位置: 首页>>代码示例>>PHP>>正文


PHP PDOStatement::setFetchMode方法代码示例

本文整理汇总了PHP中PDOStatement::setFetchMode方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement::setFetchMode方法的具体用法?PHP PDOStatement::setFetchMode怎么用?PHP PDOStatement::setFetchMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PDOStatement的用法示例。


在下文中一共展示了PDOStatement::setFetchMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * @return bool
  *
  * @todo probably we can unset query an params to free up memory
  */
 protected function execute()
 {
     $this->statement = $this->dbh->prepare($this->query);
     // set fetchMode to assoc, it is easier to copy data from an array than an object
     $this->statement->setFetchMode(PDO::FETCH_ASSOC);
     return $this->statement->execute($this->params);
 }
开发者ID:rrelmy,项目名称:rorm,代码行数:12,代码来源:Query.php

示例2: Connect

 /**
  * ****************************************
  * *********** PRIVATE METHODS ************
  * ****************************************
  */
 private function Connect()
 {
     $this->Conn = parent::getConn();
     $this->Read = $this->Conn->prepare($this->Select);
     // Retornar resultados em arrays
     $this->Read->setFetchMode(PDO::FETCH_ASSOC);
 }
开发者ID:BrunoDuarte,项目名称:WS_PHP_ADMIN,代码行数:12,代码来源:Read.class.php

示例3: _fetchAll

 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);
             }
     }
 }
开发者ID:shen2,项目名称:mypdo,代码行数:32,代码来源:Statement.php

示例4: rewind

 function rewind()
 {
     $this->PDOStatement = $this->pdo->prepare($this->sql . ' ' . $this->ordersql . ' ' . $this->limitsql);
     $this->PDOStatement->execute($this->params);
     $this->PDOStatement->setFetchMode(PDO::FETCH_ASSOC);
     $this->position = 0;
 }
开发者ID:boofw,项目名称:phpole,代码行数:7,代码来源:Cursor.php

示例5: __construct

 /**
  * @param \PDOStatement $pdoStatement
  * @param string $classname optional
  */
 public function __construct($pdoStatement, $classname = '\\StdClass')
 {
     $this->pdoStatement = $pdoStatement;
     $this->count = $this->pdoStatement->rowCount();
     $this->classname = $classname;
     $this->pdoStatement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->classname);
 }
开发者ID:scandio,项目名称:troba,代码行数:11,代码来源:ResultSet.php

示例6: __construct

 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     try {
         if (substr($queryString, 0, 2) === '::') {
             $connection->getPdo()->{substr($queryString, 2)}();
         } elseif ($queryString !== NULL) {
             static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
             $this->pdoStatement = $connection->getPdo()->prepare($queryString);
             foreach ($params as $key => $value) {
                 $type = gettype($value);
                 $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR);
             }
             $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
             $this->pdoStatement->execute();
         }
     } catch (\PDOException $e) {
         $e = $this->supplementalDriver->convertException($e);
         $e->queryString = $queryString;
         throw $e;
     }
     $this->time = microtime(TRUE) - $time;
 }
开发者ID:nette,项目名称:database,代码行数:27,代码来源:ResultSet.php

示例7: Connect

 /**
  * PRIVATE METODOS
  */
 private function Connect()
 {
     /** Pega a Conexão com a Class Pai Conn e atribui ao $this->Conn */
     $this->Conn = parent::getConn();
     /** Cria o Prepare Statement do Select */
     $this->Read = $this->Conn->prepare($this->Select);
     /** Seta o retorno dos dados no Formato fetch_assoc */
     $this->Read->setFetchMode(PDO::FETCH_ASSOC);
 }
开发者ID:hsnunes,项目名称:drmeatende,代码行数:12,代码来源:Read.class.php

示例8: execute

 public function execute()
 {
     try {
         $this->stmt->execute();
         $this->stmt->setFetchMode(PDO::FETCH_ASSOC);
         ++self::$queryCount;
     } catch (PDOException $e) {
         echo $this->stmt->queryString;
         throw $e;
     }
 }
开发者ID:thezawad,项目名称:vakuum,代码行数:11,代码来源:Query.php

示例9: query

 /**
  * Run a query against a database.  Get a result
  * @param string $query The SQL to run against the database
  * @param array $args An associative array of query parameters
  * @return bool|\PDOStatement False if query fails, results in this database's fetch_class if successful
  * @throws \Exception
  */
 public function query($query, $args = array())
 {
     if (!empty($this->pdo_statement)) {
         $this->pdo_statement->closeCursor();
     }
     if ($this->pdo_statement = $this->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true))) {
         $this->pdo_statement->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, $this->fetch_class, [$this]);
         if (!$this->pdo_statement->execute($args)) {
             throw new \Exception($this->pdo_statement->errorInfo());
         }
         return true;
     } else {
         throw new \Exception($this->errorInfo());
     }
 }
开发者ID:ringmaster,项目名称:microsite2,代码行数:22,代码来源:DB.php

示例10:

 function __construct(SblamBase $base, PDOStatement $pdo)
 {
     $this->base = $base;
     $this->pdo = $pdo;
     $pdo->setFetchMode(PDO::FETCH_ASSOC);
     $this->next();
 }
开发者ID:bitemyapp,项目名称:Sblam,代码行数:7,代码来源:sblambase.php

示例11: setStatement

 /**
  * @param \PDOStatement $statement
  * @param int           $fetchMode
  *
  * @return \Kisma\Core\Tools\DataReader
  */
 public function setStatement($statement, $fetchMode = \PDO::FETCH_ASSOC)
 {
     if (null !== ($this->_statement = $statement)) {
         $this->_statement->setFetchMode($fetchMode);
     }
     return $this;
 }
开发者ID:kisma,项目名称:kisma,代码行数:13,代码来源:DataReader.php

示例12: _set_fetch_mode

 /**
  *  Sets the fetch mode.
  *
  *  @param string $fetch_style   Controls how the rows will be returned.
  *  @param obj $obj              The object to be fetched into for use with FETCH_INTO.
  *  @access protected
  *  @return int
  */
 protected function _set_fetch_mode($fetch_style, $obj = null)
 {
     switch ($fetch_style) {
         case 'assoc':
             $this->_statement->setFetchMode(\PDO::FETCH_ASSOC);
             break;
         case 'both':
             $this->_statement->setFetchMode(\PDO::FETCH_BOTH);
             break;
         case 'into':
             $this->_statement->setFetchMode(\PDO::FETCH_INTO, $obj);
             break;
         case 'lazy':
             $this->_statement->setFetchMode(\PDO::FETCH_LAZY);
             break;
         case 'num':
             $this->_statement->setFetchMode(\PDO::FETCH_NUM);
             break;
         case 'obj':
             $this->_statement->setFetchMode(\PDO::FETCH_OBJ);
             break;
         default:
             $this->_statement->setFetchMode(\PDO::FETCH_ASSOC);
             break;
     }
 }
开发者ID:nbeletsky,项目名称:nx,代码行数:34,代码来源:PDO_MySQL.php

示例13: __construct

 public function __construct(Connection $connection, $queryString, array $params)
 {
     $time = microtime(TRUE);
     $this->connection = $connection;
     $this->supplementalDriver = $connection->getSupplementalDriver();
     $this->queryString = $queryString;
     $this->params = $params;
     if (substr($queryString, 0, 2) === '::') {
         $connection->getPdo()->{substr($queryString, 2)}();
     } elseif ($queryString !== NULL) {
         $this->pdoStatement = $connection->getPdo()->prepare($queryString);
         $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC);
         $this->pdoStatement->execute($params);
     }
     $this->time = microtime(TRUE) - $time;
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:16,代码来源:ResultSet.php

示例14: setFetchMode

 /**
  * Changes the fetching mode affecting \Phalcon\Db\Result\Pdo::fetch()
  *
  *<code>
  *  //Return array with integer indexes
  *  $result->setFetchMode(Phalcon\Db::FETCH_NUM);
  *
  *  //Return associative array without integer indexes
  *  $result->setFetchMode(Phalcon\Db::FETCH_ASSOC);
  *
  *  //Return associative array together with integer indexes
  *  $result->setFetchMode(Phalcon\Db::FETCH_BOTH);
  *
  *  //Return an object
  *  $result->setFetchMode(Phalcon\Db::FETCH_OBJ);
  *</code>
  *
  * @param int $fetchMode
  * @throws Exception
  */
 public function setFetchMode($fetchMode)
 {
     if (is_int($fetchMode) === false) {
         throw new Exception('Invalid parameter type.');
     }
     switch ($fetchMode) {
         case 1:
             $fetchType = 2;
             break;
         case 2:
             $fetchType = 4;
             break;
         case 3:
             $fetchType = 3;
             break;
         case 4:
             $fetchType = 5;
             break;
         default:
             $fetchType = 0;
             break;
     }
     if ($fetchType !== 0) {
         $this->_pdoStatement->setFetchMode($fetchType);
         $this->_fetchMode = $fetchType;
     }
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:47,代码来源:Pdo.php

示例15: fetchObject

 /**
  * Получение объекта из запроса
  * @return Item
  */
 public function fetchObject(\PDOStatement $statement)
 {
     $statement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->getItemClass(), array($this->getManager(), $this->getTable(), false));
     /** @var Item $obj */
     $obj = $statement->fetch();
     return $obj;
 }
开发者ID:sqrt-pro,项目名称:db,代码行数:11,代码来源:Repository.php


注:本文中的PDOStatement::setFetchMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。