Skip to content

Latest commit

 

History

History
81 lines (61 loc) · 2.55 KB

pdostatement-fetchall.md

File metadata and controls

81 lines (61 loc) · 2.55 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic
PDOStatement::fetchAll
API reference for the PDOStatement::fetchAll function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server.
David-Engel
davidengel
08/10/2020
sql
connectivity
reference

PDOStatement::fetchAll

[!INCLUDEDriver_PHP_Download]

Returns the rows in a result set in an array.

Syntax

  
array PDOStatement::fetchAll([ $fetch_style[, $column_index ][, ctor_args]] );  

Parameters

$fetch_style: An (integer) symbol specifying the format of the row data. See PDOStatement::fetch for a list of values. PDO::FETCH_COLUMN is also allowed. PDO::FETCH_BOTH is the default.

$column_index: An integer value representing the column to return if $fetch_style is PDO::FETCH_COLUMN. 0 is the default.

$ctor_args: An array of the parameters for a class constructor, when $fetch_style is PDO::FETCH_CLASS or PDO::FETCH_OBJ.

Return Value

An array of the remaining rows in the result set, or false if the method call fails.

Remarks

Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].

Example

<?php  
   $server = "(local)";  
   $database = "AdventureWorks";  
   $conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");  
  
   print "-----------\n";  
   $stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );  
   $result = $stmt->fetchall(PDO::FETCH_BOTH);  
   print_r( $result );  
   print "\n-----------\n";  
  
   print "-----------\n";  
   $stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );  
   $result = $stmt->fetchall(PDO::FETCH_NUM);  
   print_r( $result );  
   print "\n-----------\n";  
  
   $stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );  
   $result = $stmt->fetchall(PDO::FETCH_COLUMN, 1);  
   print_r( $result );  
   print "\n-----------\n";  
  
   class cc {  
      function __construct( $arg ) {  
         echo "$arg\n";  
      }  
  
      function __toString() {  
         echo "To string\n";  
      }  
   };  
  
   $stmt = $conn->query( 'SELECT TOP(2) * FROM Person.ContactType' );  
   $all = $stmt->fetchAll( PDO::FETCH_CLASS, 'cc', array( 'Hi!' ));  
   var_dump( $all );  
?>  

See Also

PDOStatement Class

PDO