445 lines
17 KiB
PHP
445 lines
17 KiB
PHP
--TEST--
|
||
Test the PDOStatement::fetchAll() method with various arguments (Note: FETCH_LAZY/FETCH_INTO/FETCH_BOUND are not tested).
|
||
--SKIPIF--
|
||
<?php require('skipif.inc'); ?>
|
||
--FILE--
|
||
<?php
|
||
|
||
require_once 'MsCommon.inc';
|
||
|
||
|
||
function fetchAll_rows( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
|
||
$result = $stmt->fetchAll();
|
||
var_dump($result);
|
||
}
|
||
|
||
function fetchAll_column( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
$result = $stmt->fetchAll(PDO::FETCH_COLUMN, 5);
|
||
var_dump($result);
|
||
}
|
||
|
||
function fetchAll_types( $conn )
|
||
{
|
||
global $table2;
|
||
$stmt = $conn->query( "Select * from ". $table2 );
|
||
$result = $stmt->fetchAll();
|
||
var_dump ($result);
|
||
}
|
||
|
||
function fetchAll_both( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
$result = $stmt->fetchAll(PDO::FETCH_BOTH);
|
||
var_dump($result[0]);
|
||
$stmt->closeCursor();
|
||
}
|
||
|
||
function fetchAll_assoc( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||
var_dump($result[0]);
|
||
$stmt->closeCursor();
|
||
}
|
||
|
||
function fetchAll_obj( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
|
||
var_dump($result[1]);
|
||
$stmt->closeCursor();
|
||
}
|
||
|
||
function fetchAll_num( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
$result = $stmt->fetchAll(PDO::FETCH_NUM);
|
||
var_dump($result[1]);
|
||
$stmt->closeCursor();
|
||
}
|
||
|
||
function fetchAll_class( $conn )
|
||
{
|
||
global $table1;
|
||
global $table1_class;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
$result = $stmt->fetchAll(PDO::FETCH_CLASS, $table1_class);
|
||
$result[1]->dumpAll();
|
||
$stmt->closeCursor();
|
||
}
|
||
|
||
function fetchAll_invalid( $conn )
|
||
{
|
||
global $table1;
|
||
$stmt = $conn->query( "Select * from ". $table1 );
|
||
try
|
||
{
|
||
$result = $stmt->fetchAll(PDO::FETCH_UNKNOWN);
|
||
}
|
||
catch(PDOException $err)
|
||
{
|
||
print_r($err);
|
||
}
|
||
}
|
||
|
||
try
|
||
{
|
||
$db = connect();
|
||
create_and_insert_table1( $db );
|
||
create_and_insert_table2( $db );
|
||
echo "Test_1 : fetch from a table with multiple rows :\n";
|
||
fetchAll_rows($db);
|
||
echo "Test_2 : fetch all values of a single column :\n";
|
||
fetchAll_column($db);
|
||
echo "Test_3 : fetch all SQL types except TimeStamp and Variant :\n";
|
||
fetchAll_types($db);
|
||
echo "Test_4 : FETCH_BOTH :\n";
|
||
fetchAll_both($db);
|
||
echo "Test_5 : FETCH_ASSOC :\n";
|
||
fetchAll_assoc($db);
|
||
echo "Test_6 : FETCH_OBJ :\n";
|
||
fetchAll_obj($db);
|
||
echo "Test_7 : FETCH_NUM :\n";
|
||
fetchAll_num($db);
|
||
echo "Test_8 : FETCH_CLASS :\n";
|
||
fetchAll_class($db);
|
||
echo "Test_9 : FETCH_INVALID :\n";
|
||
fetchAll_invalid($db);
|
||
}
|
||
catch( PDOException $e ) {
|
||
var_dump( $e );
|
||
exit;
|
||
}
|
||
|
||
|
||
?>
|
||
--EXPECTF--
|
||
Test_1 : fetch from a table with multiple rows :
|
||
array(2) {
|
||
[0]=>
|
||
array(16) {
|
||
["IntCol"]=>
|
||
string(1) "1"
|
||
[0]=>
|
||
string(1) "1"
|
||
["CharCol"]=>
|
||
string(10) "STRINGCOL1"
|
||
[1]=>
|
||
string(10) "STRINGCOL1"
|
||
["NCharCol"]=>
|
||
string(10) "STRINGCOL1"
|
||
[2]=>
|
||
string(10) "STRINGCOL1"
|
||
["DateTimeCol"]=>
|
||
string(23) "2000-11-11 11:11:11.110"
|
||
[3]=>
|
||
string(23) "2000-11-11 11:11:11.110"
|
||
["VarcharCol"]=>
|
||
string(10) "STRINGCOL1"
|
||
[4]=>
|
||
string(10) "STRINGCOL1"
|
||
["NVarCharCol"]=>
|
||
string(10) "STRINGCOL1"
|
||
[5]=>
|
||
string(10) "STRINGCOL1"
|
||
["FloatCol"]=>
|
||
string(7) "111.111"
|
||
[6]=>
|
||
string(7) "111.111"
|
||
["XmlCol"]=>
|
||
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
|
||
[7]=>
|
||
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
|
||
}
|
||
[1]=>
|
||
array(16) {
|
||
["IntCol"]=>
|
||
string(1) "2"
|
||
[0]=>
|
||
string(1) "2"
|
||
["CharCol"]=>
|
||
string(10) "STRINGCOL2"
|
||
[1]=>
|
||
string(10) "STRINGCOL2"
|
||
["NCharCol"]=>
|
||
string(10) "STRINGCOL2"
|
||
[2]=>
|
||
string(10) "STRINGCOL2"
|
||
["DateTimeCol"]=>
|
||
string(23) "2000-11-11 11:11:11.223"
|
||
[3]=>
|
||
string(23) "2000-11-11 11:11:11.223"
|
||
["VarcharCol"]=>
|
||
string(10) "STRINGCOL2"
|
||
[4]=>
|
||
string(10) "STRINGCOL2"
|
||
["NVarCharCol"]=>
|
||
string(10) "STRINGCOL2"
|
||
[5]=>
|
||
string(10) "STRINGCOL2"
|
||
["FloatCol"]=>
|
||
string(18) "222.22200000000001"
|
||
[6]=>
|
||
string(18) "222.22200000000001"
|
||
["XmlCol"]=>
|
||
string(431) "<xml> 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
|
||
[7]=>
|
||
string(431) "<xml> 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
|
||
}
|
||
}
|
||
Test_2 : fetch all values of a single column :
|
||
array(2) {
|
||
[0]=>
|
||
string(10) "STRINGCOL1"
|
||
[1]=>
|
||
string(10) "STRINGCOL2"
|
||
}
|
||
Test_3 : fetch all SQL types except TimeStamp and Variant :
|
||
array(1) {
|
||
[0]=>
|
||
array(62) {
|
||
["BigIntCol"]=>
|
||
string(1) "1"
|
||
[0]=>
|
||
string(1) "1"
|
||
["BinaryCol"]=>
|
||
string(5) " |