Class Phalcon\Db\Result\Pdo

implements Phalcon\Db\ResultInterface

Source on GitHub

Encapsulates the resultset internals

  1. <?php
  2. $result = $connection->query("SELECT * FROM robots ORDER BY name");
  3. $result->setFetchMode(
  4. \Phalcon\Db::FETCH_NUM
  5. );
  6. while ($robot = $result->fetchArray()) {
  7. print_r($robot);
  8. }

Methods

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

Phalcon\Db\Result\Pdo constructor

public execute ()

Allows to execute 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 fetch ([mixed $fetchStyle], [mixed $cursorOrientation], [mixed $cursorOffset])

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

  1. <?php
  2. $result = $connection->query("SELECT * FROM robots ORDER BY name");
  3. $result->setFetchMode(
  4. \Phalcon\Db::FETCH_OBJ
  5. );
  6. while ($robot = $result->fetch()) {
  7. echo $robot->name;
  8. }

public 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

  1. <?php
  2. $result = $connection->query("SELECT * FROM robots ORDER BY name");
  3. $result->setFetchMode(
  4. \Phalcon\Db::FETCH_NUM
  5. );
  6. while ($robot = result->fetchArray()) {
  7. print_r($robot);
  8. }

public fetchAll ([mixed $fetchStyle], [mixed $fetchArgument], [mixed $ctorArgs])

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

  1. <?php
  2. $result = $connection->query(
  3. "SELECT * FROM robots ORDER BY name"
  4. );
  5. $robots = $result->fetchAll();

public numRows ()

Gets number of rows returned by a resultset

  1. <?php
  2. $result = $connection->query(
  3. "SELECT * FROM robots ORDER BY name"
  4. );
  5. echo "There are ", $result->numRows(), " rows in the resultset";

public dataSeek (mixed $number)

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

  1. <?php
  2. $result = $connection->query(
  3. "SELECT * FROM robots ORDER BY name"
  4. );
  5. // Move to third row on result
  6. $result->dataSeek(2);
  7. // Fetch third row
  8. $row = $result->fetch();

public setFetchMode (mixed $fetchMode, [mixed $colNoOrClassNameOrObject], [mixed $ctorargs])

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

  1. <?php
  2. // Return array with integer indexes
  3. $result->setFetchMode(
  4. \Phalcon\Db::FETCH_NUM
  5. );
  6. // Return associative array without integer indexes
  7. $result->setFetchMode(
  8. \Phalcon\Db::FETCH_ASSOC
  9. );
  10. // Return associative array together with integer indexes
  11. $result->setFetchMode(
  12. \Phalcon\Db::FETCH_BOTH
  13. );
  14. // Return an object
  15. $result->setFetchMode(
  16. \Phalcon\Db::FETCH_OBJ
  17. );

public getInternalResult ()

Gets the internal PDO result object