배열의 결과 집합에 있는 행을 반환합니다.
구문
array PDOStatement::fetchAll([ $fetch_style[, $column_index ][, ctor_args]] );
매개 변수
$ fetch_style: 행 데이터의 형식을 지정하는 (정수) 기호입니다. 값 목록은 PDOStatement::fetch를 참조하세요. PDO::FETCH_COLUMN도 허용됩니다. PDO::FETCH_BOTH 기본값입니다.
$ column_index: $fetch_style PDO::FETCH_COLUMN 경우 반환할 열을 나타내는 정수 값입니다. 기본값은 0입니다.
$ ctor_args: $fetch_style PDO::FETCH_CLASS 또는 PDO::FETCH_OBJ 클래스 생성자에 대한 매개 변수 배열입니다.
반환 값
결과 집합에 있는 나머지 행의 배열이거나 메서드 호출이 실패하면 false입니다.
설명
Microsoft Drivers for PHP for SQL Server의 2.0 버전에서 PDO에 대한 지원이 추가되었습니다.
예시
<?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 );
?>