W3cubDocs

/Phalcon 2

Class Phalcon\Db\Result\Pdo

Encapsulates the resultset internals

$result = $connection->query("SELECT * FROM robots ORDER BY name");
$result->setFetchMode(Phalcon\Db::FETCH_NUM);
while ($robot = $result->fetchArray()) {
    print_r($robot);
}

Methods

public __construct (Phalcon\Db\AdapterInterface $connection, PDOStatement $result, [string $sqlStatement], [array $bindParams], [array $bindTypes])

Phalcon\Db\Result\Pdo constructor

public boolean execute ()

Allows to executes the statement again. Some database systems don’t support scrollable cursors, So, as cursors are forward only, we need to execute the cursor again to fetch rows from the begining

public mixed fetch ()

Fetches an array/object of strings that corresponds to the fetched row, or FALSE if there are no more rows. This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode

$result = $connection->query("SELECT * FROM robots ORDER BY name");
$result->setFetchMode(Phalcon\Db::FETCH_OBJ);
while ($robot = $result->fetch()) {
    echo $robot->name;
}

public mixed fetchArray ()

Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows. This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode

$result = $connection->query("SELECT * FROM robots ORDER BY name");
$result->setFetchMode(Phalcon\Db::FETCH_NUM);
while ($robot = $result->fetchArray()) {
    print_r($robot);
}

public array fetchAll ()

Returns an array of arrays containing all the records in the result This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode

$result = $connection->query("SELECT * FROM robots ORDER BY name");
$robots = $result->fetchAll();

public int numRows ()

Gets number of rows returned by a resulset

$result = $connection->query("SELECT * FROM robots ORDER BY name");
echo 'There are ', $result->numRows(), ' rows in the resulset';

public dataSeek (int $number)

Moves internal resulset cursor to another position letting us to fetch a certain row

$result = $connection->query("SELECT * FROM robots ORDER BY name");
$result->dataSeek(2); // Move to third row on result
$row = $result->fetch(); // Fetch third row

public setFetchMode (int $fetchMode, [unknown $fetchArg1], [unknown $fetchArg2])

Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch()

//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);

public PDOStatement getInternalResult ()

Gets the internal PDO result object

public boolean nextRowset ()

Advances to the next rowset in a multi-rowset statement handle

© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Db_Result_Pdo.html