本文整理汇总了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);
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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());
}
}
示例10:
function __construct(SblamBase $base, PDOStatement $pdo)
{
$this->base = $base;
$this->pdo = $pdo;
$pdo->setFetchMode(PDO::FETCH_ASSOC);
$this->next();
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}