當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。