Merge pull request #379 from yitam/functional-tests

Upload functional tests for both sqlsrv and pdo_sqlsrv
This commit is contained in:
Jenny Tam 2017-05-10 08:24:40 -07:00 committed by GitHub
commit 7c5b04e5c8
425 changed files with 35543 additions and 1662 deletions

View file

@ -68,12 +68,16 @@ RUN phpize && ./configure LDFLAGS="-lgcov" CXXFLAGS="-O0 --coverage" && make &&
# set name of sql server host to use
WORKDIR $PHPSQLDIR/test/pdo_sqlsrv
RUN sed -i -e 's/localhost/sql/g' autonomous_setup.php
RUN sed -i -e 's/<YourStrong!Passw0rd>/'"$TEST_PHP_SQL_PWD"'/g' autonomous_setup.php
RUN sed -i -e 's/TARGET_SERVER/sql/g' MsSetup.inc
RUN sed -i -e 's/TARGET_DATABASE/msphpsql_pdosqlsrv/g' MsSetup.inc
RUN sed -i -e 's/TARGET_USERNAME/'"$TEST_PHP_SQL_UID"'/g' MsSetup.inc
RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc
WORKDIR $PHPSQLDIR/test/sqlsrv
RUN sed -i -e 's/localhost/sql/g' autonomous_setup.php
RUN sed -i -e 's/<YourStrong!Passw0rd>/'"$TEST_PHP_SQL_PWD"'/g' autonomous_setup.php
RUN sed -i -e 's/TARGET_SERVER/sql/g' MsSetup.inc
RUN sed -i -e 's/TARGET_DATABASE/msphpsql_sqlsrv/g' MsSetup.inc
RUN sed -i -e 's/TARGET_USERNAME/'"$TEST_PHP_SQL_UID"'/g' MsSetup.inc
RUN sed -i -e 's/TARGET_PASSWORD/'"$TEST_PHP_SQL_PWD"'/g' MsSetup.inc
ENV REPORT_EXIT_STATUS 1
ENV TEST_PHP_EXECUTABLE /usr/bin/php

View file

@ -122,10 +122,10 @@ install:
- 7z x -y php-sdk-binary-tools-20110915.zip -o%PHP_SDK%
- 7z x -y php.zip -o%PHP_SDK_DIR%
- echo update SQL connection string
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:TEST_PHP_SQL_SERVER} -replace "<YourStrong!Passw0rd>", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:TEST_PHP_SQL_SERVER} -replace "<YourStrong!Passw0rd>", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\MsSetup.inc) | ForEach-Object { $_ -replace "TARGET_SERVER", ${env:TEST_PHP_SQL_SERVER} -replace "TARGET_DATABASE", ${env:PDOSQLSRV_DBNAME} -replace "TARGET_USERNAME", ${env:TEST_PHP_SQL_UID} -replace "TARGET_PASSWORD", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\MsSetup.inc
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\MsSetup.inc
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\MsSetup.inc) | ForEach-Object { $_ -replace "TARGET_SERVER", ${env:TEST_PHP_SQL_SERVER} -replace "TARGET_DATABASE", ${env:SQLSRV_DBNAME} -replace "TARGET_USERNAME", ${env:TEST_PHP_SQL_UID} -replace "TARGET_PASSWORD", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\MsSetup.inc
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\MsSetup.inc
build_script:
- '"C:\\Program Files (x86)\\Microsoft Visual Studio %PHP_VC%.0\\VC\\vcvarsall.bat" %BUILD_PLATFORM%'

View file

@ -49,11 +49,15 @@ def readAndPrint(inputStr, file, path):
def TestFilename(line):
terminateChar = os.sep
currentPos = 0
firstpos = len(line) * -1
while True:
currentPos = currentPos - 1
# if passed the first pos, stop
if currentPos < firstpos:
break
line[currentPos]
if line[currentPos] == terminateChar:
break
break
file = line[currentPos+1:-1]
return file

1628
test/pdo_sqlsrv/MsCommon.inc Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,65 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.
Description:
Random data generator for INSERT statements.
*/
// globals
$table1 = "PDO_Types_1";
$table2= "PDO_AllTypes";
$large_string = "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.";
$string_col = array("'STRINGCOL1'", "'STRINGCOL2'");
$date_col = array("'2000-11-11 11:11:11.111'", "'2000-11-11 11:11:11.222'");
$large_string_col = array("' 1 " . $large_string . "'", "' 2 " . $large_string . "'");
$xml_col = array("'<xml> 1 " . $large_string . "</xml>'", "'<xml> 2 " . $large_string . "</xml>'");
$binary_col = array('0x0', '0x0');
$int_col = array ( 1, 2);
$decimal_col = array (111.111, 222.222);
$guid_col = array("'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'", "'BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB'");
$null_col = 'null';
$comma = ",";
$closing_brace = "),";
class PDO_Types_1_Class{
var $IntCol;
var $CharCol;
var $NCharCol;
var $DateTimeCol;
var $VarcharCol;
var $NVarCharCol;
var $FloatCol;
var $XmlCol;
function dumpAll()
{
var_dump($this->IntCol);
var_dump($this->CharCol);
var_dump($this->NCharCol);
var_dump($this->DateTimeCol);
var_dump($this->VarcharCol);
var_dump($this->NVarCharCol);
var_dump($this->FloatCol);
var_dump($this->XmlCol);
}
}
$table1_class = 'PDO_Types_1_Class';
?>

View file

@ -0,0 +1,38 @@
<?php
/*
Microsoft SQL Server Driver for PHP/PDO - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved
Description:
Global variables defining the execution context
*/
if (isset($_ENV['MSSQL_SERVER']) || isset($_ENV['MSSQL_USER']) || isset($_ENV['MSSQL_PASSWORD'])) {
$server = $_ENV['MSSQL_SERVER'];
$uid = $_ENV['MSSQL_USER'];
$pwd = $_ENV['MSSQL_PASSWORD'];
$databaseName = $_ENV['MSSQL_DATABASE_NAME'];
$DriverName = $_ENV['MSSQL_DRIVER_NAME'];
} else {
$server = 'TARGET_SERVER';
$uid = 'TARGET_USERNAME';
$pwd = 'TARGET_PASSWORD';
$databaseName = 'TARGET_DATABASE';
$DriverName = "ODBC Driver 11 for SQL Server";
}
$driverType = true;
$PhpDriver = "ODBC Driver 11 for SQL Server";
$tableName = 'pdo_test_table';
$tableIndex = 'php_test_table_idx';
$procName = 'php_test_proc';
$fileName = 'php_test_file.dat';
$dsn = "odbc:Driver={$DriverName};Server=$server";
$connectionOptions = array();
$daasMode = false;
$marsMode = true;
$dsnMode = true;
$traceEnabled = false;
?>

View file

@ -0,0 +1,113 @@
--TEST--
PDO - Insert Nulls
--DESCRIPTION--
Test inserting nulls into nullable columns
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function InsertNullsTest($bindType)
{
include 'MsSetup.inc';
$outvar = null;
$failed = false;
Setup();
$conn = Connect();
DropTable($conn, $tableName);
CreateTable($conn, $tableName);
$stmt = $conn->query(<<<SQL
SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'
SQL
);
if ($stmt === false)
{
FatalError("Could not query for column information on table $tableName");
}
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
Trace($row['COLUMN_NAME'] . ": " . $row['IS_NULLABLE'] . "\n");
$stmt2 = $conn->prepare("INSERT INTO [$tableName] ([" . $row['COLUMN_NAME'] . "]) VALUES (:p1)");
if (strpos($row['COLUMN_NAME'], "timestamp") !== false) continue;
if (($row['IS_NULLABLE'] == 'YES') && (strpos($row['COLUMN_NAME'], "binary") !== false))
{
if ($bindType == PDO::PARAM_LOB)
{
$stmt2->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY);
$stmt2->bindValue(":p1", null, $bindType);
}
else if ($bindType == PDO::PARAM_STR)
{
$stmt2->bindParam(":p1", $outvar, $bindType, null, PDO::SQLSRV_ENCODING_BINARY);
}
}
else
{
$stmt2->bindParam(":p1", $outvar);
}
$stmt2->execute();
if ($stmt2->errorCode() !== '00000')
{
print_r($stmt2->errorInfo());
$failed = true;
}
}
DropTable($conn, $tableName);
return($failed);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$failed = null;
$testName = "PDO - Insert Nulls";
StartTest($testName);
try
{
$failed |= InsertNullsTest(PDO::PARAM_LOB);
$failed |= InsertNullsTest(PDO::PARAM_STR);
}
catch (Exception $e)
{
echo $e->getMessage();
}
if ($failed)
FatalError("Possible Regression: Could not insert NULL");
EndTest($testName);
}
Repro();
?>
--EXPECT--
Test "PDO - Insert Nulls" completed successfully.

View file

@ -0,0 +1,76 @@
--TEST--
PDO - Large Column Name Test
--DESCRIPTION--
Verifies that long column names are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
Setup();
$conn = Connect();
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
$conn->query("CREATE TABLE [$tableName] ([$columnName] int)");
$conn->query("INSERT INTO [$tableName] ([$columnName]) VALUES (5)");
$stmt = $conn->query("SELECT * from [$tableName]");
if ( null == $stmt )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
}
DropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$testName = "PDO - Large Column Name Test";
StartTest($testName);
$columnName = "a";
try
{
for ($a = 1; $a <= 128; $a++)
{
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "A";
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
EndTest($testName);
}
Repro();
?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.

View file

@ -0,0 +1,76 @@
--TEST--
PDO - Large Unicode Column Name Test
--DESCRIPTION--
Verifies that long column names in Unicode are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
Setup();
$conn = Connect();
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
$conn->query("CREATE TABLE [$tableName] ([$columnName] int)");
$conn->query("INSERT INTO [$tableName] ([$columnName]) VALUES (5)");
$stmt = $conn->query("SELECT * from [$tableName]");
if ( null == $stmt )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
}
DropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$testName = "PDO - Large Column Name Test";
StartTest($testName);
$columnName = "是";
try
{
for ($a = 1; $a <= 128; $a++)
{
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "是";
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
EndTest($testName);
}
Repro();
?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.

View file

@ -0,0 +1,82 @@
--TEST--
PDO - Max Output Params Test
--DESCRIPTION--
Fetch data as VARCHAR(MAX)
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function MaxOutputParamsTest($expected, $length)
{
include 'MsSetup.inc';
$outstr = null;
$conn = Connect();
CreateProc(
$conn,
"EXEC_TEST",
"@OUT varchar(80) output",
"SET NOCOUNT ON; select @OUT = '$expected'; return (0)
");
$sql = "execute EXEC_TEST ?";
$stmt = $conn->prepare($sql);
if ($length)
{
$stmt->bindParam(1, $outstr, PDO::PARAM_STR, 10);
}
else
{
$stmt->bindParam(1, $outstr, PDO::PARAM_STR, 3);
}
$stmt->execute();
echo "Expected: $expected Received: $outstr\n";
if ($outstr !== $expected)
{
print_r($stmt->errorInfo());
return(-1);
}
return(0);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$failed = null;
$testName = "PDO - Max Output Params Test";
StartTest($testName);
$failed |= MaxOutputParamsTest("abc", null);
$failed |= MaxOutputParamsTest("abc", -1);
if ($failed)
FatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated");
EndTest($testName);
}
Repro();
?>
--EXPECT--
Expected: abc Received: abc
Expected: abc Received: abc
Test "PDO - Max Output Params Test" completed successfully.

View file

@ -0,0 +1,60 @@
--TEST--
PDO Drivers Info Test
--DESCRIPTION--
Verifies the functionality of "PDO:getAvailableDrivers()”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function DriversInfo()
{
include 'MsSetup.inc';
$testName = "PDO - Drivers";
StartTest($testName);
$drivers = PDO::getAvailableDrivers();
if (in_array("sqlsrv", $drivers))
{
$count = count($drivers);
for ($i = 0; $i < $count; $i++)
{
Trace("Driver #".($i + 1).": ".$drivers[$i]."\n");
}
}
else
{
printf("$PhpDriver is missing.\n");
}
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
DriversInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - Drivers" completed successfully.

View file

@ -0,0 +1,61 @@
--TEST--
PDO PHP Info Test
--DESCRIPTION--
Verifies the functionality of PDO with phpinfo().
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function DriversInfo()
{
include 'MsSetup.inc';
$testName = "PDO - phpinfo";
StartTest($testName);
ob_start();
phpinfo();
$info = ob_get_contents();
ob_end_clean();
// Check phpinfo() data
if (stristr($info, "PDO support => enabled") === false)
{
printf("PDO is not enabled\n");
}
else if (stristr($info, "pdo_sqlsrv support => enabled") === false)
{
printf("Cannot find PDO driver line in phpinfo() output\n");
}
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
DriversInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - phpinfo" completed successfully.

View file

@ -0,0 +1,62 @@
--TEST--
PDO Connection Test
--DESCRIPTION--
Checks whether the driver can successfully establish a database connection.
Verifies as well that invalid connection attempts fail as expected.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ConnectionTest()
{
include 'MsSetup.inc';
$testName = "PDO Connection";
StartTest($testName);
// Invalid connection attempt => errors are expected
Trace("Invalid connection attempt (to a non-existing server) ....\n");
$conn1 = PDOConnect('PDO', "InvalidServerName", $uid, $pwd, false);
if ($conn1)
{
printf("Invalid connection attempt should have failed.\n");
}
$conn1 = null;
// Valid connection attempt => no errors are expected
Trace("\nValid connection attempt (to $server) ....\n");
$conn2 = Connect();
$conn2 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ConnectionTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection" completed successfully.

View file

@ -0,0 +1,149 @@
--TEST--
PDO Connection Pooling Test
--DESCRIPTION--
Checks whether the driver can successfully establish a database connection
when an URI-based construct is used.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_unix.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ConnectionTest()
{
include 'MsSetup.inc';
$testName = "PDO Connection Pooling";
StartTest($testName);
$optionsDefault = null;
$optionsPool = null;
$optionsNotPool = null;
if ($dsnMode)
{
$optionsDefault = "APP=Microsoft PHP;";
$optionsPool = "APP=Microsoft PHP;ConnectionPooling=1;";
$optionsNotPool = "APP=Microsoft PHP;ConnectionPooling=0;";
}
else
{
$optionsDefault = array('APP'=>'Microsoft PHP');
$optionsPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>1);
$optionsNotPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>0);
}
// Create pool
$conn1 = DoConnect($optionsPool);
$conn2 = DoConnect($optionsPool);
$conn3 = DoConnect($optionsPool);
$connId1 = ConnectionID($conn1);
$connId2 = ConnectionID($conn2);
$connId3 = ConnectionID($conn3);
$conn1 = null;
$conn2 = null;
$conn3 = null;
$conn4 = DoConnect($optionsDefault);
if (!IsPoolConnection($conn4, $connId1, $connId2, $connId3))
{
echo "Default connection was expected to be a pool connection..\n";
}
$conn4 = null;
$conn5 = DoConnect($optionsPool);
if (!IsPoolConnection($conn5, $connId1, $connId2, $connId3))
{
echo "A pool connection was expected...\n";
}
$conn5 = null;
$conn6 = DoConnect($optionsNotPool);
if (IsPoolConnection($conn6, $connId1, $connId2, $connId3))
{
echo "A pool connection was not expected...\n";
}
$conn6 = null;
EndTest($testName);
}
function DoConnect($options)
{
include 'MsSetup.inc';
$conn = null;
try
{
if ($dsnMode)
{
$conn = new PDO("sqlsrv:Server=$server;$options", $uid, $pwd);
}
else
{
$conn = new PDO("sqlsrv:Server=$server", $uid, $pwd, $options);
}
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
}
catch (PDOException $e)
{
$conn = null;
TraceEx("\nFailed to connect to $server: ".$e->getMessage(), true);
}
return ($conn);
}
function ConnectionID($conn)
{
$tsql = "SELECT @@SPID FROM master.dbo.sysprocesses WHERE (program_name='Microsoft PHP')";
$stmt = ExecuteQuery($conn, $tsql);
$connID = $stmt->fetchColumn(0);
$stmt->closeCursor();
$stmt = null;
return ($connID);
}
function IsPoolConnection($conn, $Id1, $Id2, $Id3)
{
$connID = ConnectionID($conn);
if (($connID == $Id1) || ($connID == $Id2) || ($connID == $Id3))
{
return (true);
}
return (false);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ConnectionTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Test "PDO Connection Pooling" completed successfully.

View file

@ -0,0 +1,142 @@
--TEST--
PDO Connection Pooling Test
--DESCRIPTION--
Checks whether the driver can successfully establish a database connection
when an URI-based construct is used.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_unix.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ConnectionTest($noPasses)
{
include 'MsSetup.inc';
$testName = "PDO Connection Pooling";
StartTest($testName);
$optionsPool = null;
$optionsNotPool = null;
if ($dsnMode)
{
$optionsPool = "APP=Microsoft PHP;ConnectionPooling=1;";
$optionsNotPool = "APP=Microsoft PHP;ConnectionPooling=0;";
}
else
{
$optionsPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>1);
$optionsNotPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>0);
}
// Establish a pool connection
$conn1 = DoConnect($optionsPool);
$conn1ID = ConnectionID($conn1);
$conn1 = null;
// Verifies that non-pool connections have a different id
for ($i = 0; $i < $noPasses; $i++)
{
$conn2 = DoConnect($optionsNotPool);
$conn2ID = ConnectionID($conn2);
$conn2 = null;
if ($conn1ID == $conn2ID)
{
echo "A different connection id was expected: $conn1ID => $conn2ID\n";
break;
}
$conn2 = null;
}
// Verifies that pool connections have the same id
for ($i = 0; $i < $noPasses; $i++)
{
$conn2 = DoConnect($optionsPool);
$conn2ID = ConnectionID($conn2);
$conn2 = null;
if ($conn1ID != $conn2ID)
{
echo "The same connection id was expected: $conn1ID => $conn2ID\n";
break;
}
$conn2 = null;
}
EndTest($testName);
}
function DoConnect($options)
{
include 'MsSetup.inc';
$conn = null;
try
{
if ($dsnMode)
{
$conn = new PDO("sqlsrv:Server=$server;$options", $uid, $pwd);
}
else
{
$conn = new PDO("sqlsrv:Server=$server", $uid, $pwd, $options);
}
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
}
catch (PDOException $e)
{
$conn = null;
TraceEx("\nFailed to connect to $server: ".$e->getMessage(), true);
}
return ($conn);
}
function ConnectionID($conn)
{
$query = "SELECT @@SPID FROM master.dbo.sysprocesses WHERE (program_name='Microsoft PHP')";
$connID = null;
$stmt = $conn->query($query);
$row = $stmt->fetch();
if ($row)
{
$connID = $row[0];
}
else
{
echo "Failed to retrieve connection id\n";
}
$stmt = null;
return ($connID);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ConnectionTest(5);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection Pooling" completed successfully.

View file

@ -0,0 +1,80 @@
--TEST--
PDO Test for PDO::errorCode()
--DESCRIPTION--
Verification of PDO::errorCode()
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function CheckErrorCode()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Error Code";
StartTest($testName);
$conn1 = Connect();
CheckError(1, $conn1, '00000');
// Prepare test table
$table1 = $tableName."1";
$table2 = $tableName."2";
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
// Check errors when executing SELECT queries
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
CheckError(2, $conn1);
CheckError(3, $stmt1);
$stmt1->execute();
$stmt2 = &$stmt1;
CheckError(4, $stmt1);
$stmt1->closeCursor();
DropTable($conn1, $table1);
CheckError(5, $conn1);
// Cleanup
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function CheckError($offset, &$obj, $expected = '00000')
{
$code = $obj->errorCode();
if (($code != $expected) && (($expected != '00000') || ($code !='')))
{
printf("[%03d] Expecting error code '%s' got code '%s'\n",
$offset, $expected, $code);
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
CheckErrorCode();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection - Error Code" completed successfully.

View file

@ -0,0 +1,116 @@
--TEST--
PDO Test for PDO::errorInfo()
--DESCRIPTION--
Verification of PDO::errorInfo()
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function CheckErrorInfo()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Error Info";
StartTest($testName);
$conn1 = Connect();
CheckError(1, $conn1, '00000');
// Prepare test table
$table1 = $tableName."1";
$table2 = $tableName."2";
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
// Check errors when executing SELECT queries
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
CheckError(2, $conn1);
CheckError(3, $stmt1);
$stmt1->execute();
$stmt2 = &$stmt1;
CheckError(4, $stmt1);
$stmt1->closeCursor();
//DropTable($conn1, $table1);
@$stmt1->execute();
CheckError(5, $conn1);
//CheckError(6, $stmt1, '42S02');
//CheckError(7, $stmt2, '42S02');
$stmt1->closeCursor();
DropTable($conn1, $table2);
$conn2 = &$conn1;
//@$conn1->query("SELECT id, label FROM [$table2]");
//CheckError(8, $conn1, '42S02');
//CheckError(9, $conn2, '42S02');
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
$stmt1 = $conn1->query("SELECT id, label FROM [$table1]");
CheckError(10, $conn1);
CheckError(11, $stmt1);
$stmt1->closeCursor();
// @$conn1->query("SELECT id, label FROM [$table2]");
// CheckError(12, $conn1, '42S02');
// CheckError(13, $conn2, '42S02');
CheckError(14, $stmt1);
// Cleanup
DropTable($conn1, $table1);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function CheckError($offset, &$obj, $expected = '00000')
{
$info = $obj->errorInfo();
$code = $info[0];
if (($code != $expected) && (($expected != '00000') || ($code != '')))
{
printf("[%03d] Expecting error code '%s' got code '%s'\n",
$offset, $expected, $code);
}
if ($expected != '00000')
{
if (!isset($info[1]) || ($info[1] == ''))
{
printf("[%03d] Driver-specific error code not set\n", $offset);
}
if (!isset($info[2]) || ($info[2] == ''))
{
printf("[%03d] Driver-specific error message.not set\n", $offset);
}
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
CheckErrorInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection - Error Info" completed successfully.

View file

@ -0,0 +1,77 @@
--TEST--
PDO Info Test
--DESCRIPTION--
Verifies the functionality of "getAttribute”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function AttrTest()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Attribute Info";
StartTest($testName);
$conn1 = Connect();
ShowInfo($conn1);
$conn1 = null;
EndTest($testName);
}
function ShowInfo($conn)
{
$attributes = array("AUTOCOMMIT", // Not supported
"CASE", // 0
"CLIENT_VERSION", // array
"CONNECTION_STATUS", // Not supported
"DRIVER_NAME", // sqlsrv
"ERRMODE", // 0
"ORACLE_NULLS", // 0
"PERSISTENT", // false
"PREFETCH", // Not supported
"SERVER_INFO", // array
"SERVER_VERSION", // string
"STATEMENT_CLASS", // array
"STRINGIFY_FETCHES", // false
"TIMEOUT"); // Not supported
foreach ($attributes as $val)
{
$att = "PDO::ATTR_$val";
$attKey = constant($att);
$attVal = $conn->getAttribute($attKey);
Trace("$att ($attKey): [$attVal]\n");
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
AttrTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute

View file

@ -0,0 +1,77 @@
--TEST--
PDO Test for read-only attributes
--DESCRIPTION--
Verification of read-only attributes
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ReadOnly()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Attribute";
StartTest($testName);
$conn1 = Connect();
$conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
CheckAttribute($conn1, "PDO::ATTR_CLIENT_VERSION");
CheckAttribute($conn1, "PDO::ATTR_DRIVER_NAME");
CheckAttribute($conn1, "PDO::ATTR_SERVER_INFO");
CheckAttribute($conn1, "PDO::ATTR_SERVER_VERSION");
// Cleanup
$conn1 = null;
EndTest($testName);
}
function CheckAttribute($conn, $attName)
{
$att = constant($attName);
// Attribute value is a non-empty string
$value1 = $conn->getAttribute($att);
// Attribute is read-only
if ($conn->setAttribute($att, $value1) !== false)
{
printf("Attribute $attName must be read-only\n");
}
// Attribute value should not change
$value2 = $conn->getAttribute($att);
if ($value2 !== $value1)
{
printf("Value of attribute $attName should not change from '%s' to '%s'\n", $value1, $value2);
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ReadOnly();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection - Attribute" completed successfully.

View file

@ -0,0 +1,149 @@
--TEST--
PDO Test for PDO::ATTR_CASE
--DESCRIPTION--
Verification of fetch behavior when using PDO::ATTR_CASE.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Case Attribute";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "ID int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Retrieve data as array with no change on columns case
$conn1->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
$stmt1->closeCursor();
// Retrieve data as array with lower case columns
$conn1->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
$stmt1->closeCursor();
// Retrieve data as array with upper case columns
$conn1->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
$stmt1->closeCursor();
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(2) {
["ID"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
array(2) {
["ID"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
array(2) {
["ID"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
}
array(3) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
array(2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
}
array(3) {
[0]=>
array(2) {
["ID"]=>
string(1) "1"
["VAL"]=>
string(1) "A"
}
[1]=>
array(2) {
["ID"]=>
string(1) "2"
["VAL"]=>
string(1) "B"
}
[2]=>
array(2) {
["ID"]=>
string(1) "3"
["VAL"]=>
string(1) "C"
}
}
Test "PDO Connection - Case Attribute" completed successfully.

View file

@ -0,0 +1,98 @@
--TEST--
PDO Interface Test
--DESCRIPTION--
Verifies the compliance of the PDO API Interface.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ConnInfo()
{
include 'MsSetup.inc';
$testName = "PDO - Interface";
StartTest($testName);
$conn1 = Connect();
CheckInterface($conn1);
$conn1 = null;
EndTest($testName);
}
function CheckInterface($conn)
{
$expected = array(
'getAvailableDrivers' => true,
'__construct' => true,
'errorCode' => true,
'errorInfo' => true,
'getAttribute' => true,
'setAttribute' => true,
'beginTransaction' => true,
'commit' => true,
'rollBack' => true,
'exec' => true,
'query' => true,
'prepare' => true,
'lastInsertId' => true,
'quote' => true,
'__wakeup' => true,
'__sleep' => true,
'inTransaction' => true,
);
$classname = get_class($conn);
$methods = get_class_methods($classname);
foreach ($methods as $k => $method)
{
if (isset($expected[$method]))
{
unset($expected[$method]);
unset($methods[$k]);
}
if ($method == $classname)
{
unset($expected['__construct']);
unset($methods[$k]);
}
}
if (!empty($expected))
{
printf("Dumping missing class methods\n");
var_dump($expected);
}
if (!empty($methods))
{
printf("Found more methods than expected, dumping list\n");
var_dump($methods);
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ConnInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - Interface" completed successfully.

View file

@ -0,0 +1,93 @@
--TEST--
PDO Exec Test
--DESCRIPTION--
Basic verification for PDO::exec().
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Connection - Exec";
StartTest($testName);
$conn1 = Connect();
$dbName1 = $databaseName."1";
$dbName2 = $databaseName."2";
CreateDB($conn1, $dbName1);
DoExec(1, $conn1, "ALTER DATABASE [$dbName1] MODIFY NAME = [$dbName2]", 0);
DoExec(2, $conn1, "DROP DATABASE [$dbName2]", 0);
CreateTableEx($conn1, $tableName, "id INT, val CHAR(10)", null);
DoExec(3, $conn1, "CREATE INDEX [$tableIndex] ON [$tableName](id)", 0);
DoExec(4, $conn1, "DROP INDEX [$tableIndex] ON [$tableName]", 0);
DoExec(5, $conn1, "ALTER TABLE [$tableName] DROP COLUMN id", 0);
DoExec(6, $conn1, "ALTER TABLE [$tableName] ADD id INT", 0);
DoExec(7, $conn1, "INSERT INTO [$tableName] (id, val) VALUES (1, 'ABC')", 1);
// Cleanup
DropTable($conn1, $tableName);
DropDB($conn1, $dbName1);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function DoExec($offset, &$conn, $tsql, $expected)
{
$ret = false;
try
{
$actual = @$conn->exec($tsql);
if ($actual === $expected)
{
$ret = true;
}
else
{
printf("[%03d] Expecting '%s' (%s) instead of '%s' (%s) when executing '%s', [%s] %s\n",
$offset, $expected, gettype($expected), $actual, gettype($actual),
$tsql, $conn->errorCode(), implode(' ', $conn->errorInfo()));
}
}
catch (PDOException $e)
{
printf("[%03d] Execution of '%s' has failed, [%s] %s\n",
$offset, $tsql, $conn->errorCode(), implode(' ', $conn->errorInfo()));
}
return ($ret);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Connection - Exec" completed successfully.

View file

@ -0,0 +1,132 @@
--TEST--
PDO Basic Statement Test
--DESCRIPTION--
Basic verification for PDOStatement.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, grp";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'Group2'", null);
$tsql = "SELECT val, grp FROM [$tableName]";
// Testing prepared query
$stmt1 = ExecuteQueryEx($conn1, $tsql, false);
$stmt1->setFetchMode(PDO::FETCH_NUM);
foreach ($stmt1 as $data)
{
var_dump($data);
}
unset($stmt1);
// Testing direct query
$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test');
foreach ($stmt1 as $data)
{
var_dump($data);
}
unset($stmt1);
$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test', array('WOW'));
foreach ($stmt1 as $data)
{
var_dump($data);
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
function __construct($name = 'N/A')
{
echo __METHOD__ . "($name)\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
array(2) {
[0]=>
string(1) "A"
[1]=>
string(6) "Group1"
}
array(2) {
[0]=>
string(1) "B"
[1]=>
string(6) "Group2"
}
Test::__construct(N/A)
object(Test)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
Test::__construct(N/A)
object(Test)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
string(6) "Group2"
}
Test::__construct(WOW)
object(Test)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
Test::__construct(WOW)
object(Test)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
string(6) "Group2"
}
Test "PDO Statement" completed successfully.

View file

@ -0,0 +1,100 @@
--TEST--
PDOStatement Interface Test
--DESCRIPTION--
Verifies the compliance of the PDOStatement API Interface.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function StmtInfo()
{
include 'MsSetup.inc';
$testName = "PDOStatement - Interface";
StartTest($testName);
$conn1 = Connect();
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
$stmt1 = ExecuteQuery($conn1, "SELECT * FROM [$tableName]");
CheckInterface($stmt1);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function CheckInterface($stmt)
{
$expected = array(
'errorCode' => true,
'errorInfo' => true,
'getAttribute' => true,
'setAttribute' => true,
'debugDumpParams' => true,
'bindColumn' => true,
'bindParam' => true,
'bindValue' => true,
'closeCursor' => true,
'columnCount' => true,
'execute' => true,
'setFetchMode' => true,
'fetch' => true,
'fetchAll' => true,
'fetchColumn' => true,
'fetchObject' => true,
'getColumnMeta' => true,
'nextRowset' => true,
'rowCount' => true,
'__wakeup' => true,
'__sleep' => true,
);
$classname = get_class($stmt);
$methods = get_class_methods($classname);
foreach ($methods as $k => $method)
{
if (isset($expected[$method]))
{
unset($expected[$method]);
unset($methods[$k]);
}
}
if (!empty($expected))
{
printf("Dumping missing class methods\n");
var_dump($expected);
}
if (!empty($methods))
{
printf("Found more methods than expected, dumping list\n");
var_dump($methods);
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
StmtInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDOStatement - Interface" completed successfully.

View file

@ -0,0 +1,105 @@
--TEST--
PDO Statement Execution Test
--DESCRIPTION--
Basic verification for "PDOStatement::execute()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Execute";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'));
// Insert using question mark placeholders
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
// Count inserted rows
$stmt2 = PrepareQuery($conn1, "SELECT COUNT(id) FROM [$tableName]");
$stmt2->execute();
$num = $stmt2->fetchColumn();
echo 'There are ' . $num . " rows in the table.\n";
$stmt2->closeCursor();
// Insert using named parameters
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(:first, :second, :third)");
foreach ($data as $row)
{
$stmt1->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1], ':third'=>$row[2]));
}
unset($stmt1);
$stmt2->execute();
$num = $stmt2->fetchColumn();
unset($stmt2);
echo 'There are ' . $num . " rows in the table.\n";
// Fetch
$stmt1 = PrepareQuery($conn1, "SELECT TOP(1) :param FROM [$tableName] ORDER BY id ASC");
$stmt1->execute(array(':param' => 'ID'));
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
$stmt1->closeCursor();
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$stmt2 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
There are 6 rows in the table.
There are 12 rows in the table.
array(1) {
[0]=>
array(1) {
[""]=>
string(2) "ID"
}
}
Test "PDO Statement - Execute" completed successfully.

View file

@ -0,0 +1,75 @@
--TEST--
PDO Columns Count Test
--DESCRIPTION--
Basic verification for "PDOStatement::columnCount()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Column Count";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C', 'C'", null);
$tsql1 = "SELECT id, val FROM [$tableName]";
$tsql2 = "SELECT id, val, val2 FROM [$tableName]";
$tsql3 = "SELECT COUNT(*) FROM [$tableName]";
// Testing with direct query
foreach (array($tsql1, $tsql2, $tsql3) as $tsql)
{
$stmt1 = ExecuteQuery($conn1, $tsql);
$res = $stmt1->columnCount();
echo "Counted $res columns.\n";
unset($stmt1);
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Counted 2 columns.
Counted 3 columns.
Counted 1 columns.
Test "PDO Statement - Column Count" completed successfully.

View file

@ -0,0 +1,157 @@
--TEST--
PDO Column Metadata Test
--DESCRIPTION--
Verification for "PDOStatenent::getColumnMetadata".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Column Metadata";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'));
// Insert using question mark placeholders
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
// Retrieve column metadata via a SELECT query
$stmt1 = ExecuteQuery($conn1, "SELECT id, val, val2 FROM [$tableName]");
$md = $stmt1->getColumnMeta(0);
var_dump($md);
$md = $stmt1->getColumnMeta(1);
var_dump($md);
$md = $stmt1->getColumnMeta(2);
var_dump($md);
unset($stmt1);
// Retrieve column metadata as returned by a COUNT query
$stmt1 = ExecuteQuery($conn1, "SELECT COUNT(*) FROM [$tableName]");
$md = $stmt1->getColumnMeta(0);
var_dump($md);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(3) "int"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(2) "id"
["len"]=>
int(10)
["precision"]=>
int(0)
}
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(7) "varchar"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(3) "val"
["len"]=>
int(10)
["precision"]=>
int(0)
}
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(7) "varchar"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(4) "val2"
["len"]=>
int(16)
["precision"]=>
int(0)
}
array(8) {
["flags"]=>
int(0)
["sqlsrv:decl_type"]=>
string(3) "int"
["native_type"]=>
string(6) "string"
["table"]=>
string(0) ""
["pdo_type"]=>
int(2)
["name"]=>
string(0) ""
["len"]=>
int(10)
["precision"]=>
int(0)
}
Test "PDO Statement - Column Metadata" completed successfully.

View file

@ -0,0 +1,85 @@
--TEST--
PDO Row Count Test
--DESCRIPTION--
Verification for "PDOStatement::rowCount()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function RowCountTest()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Row Count";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
// Check row count
$tsql1 = "SELECT id FROM [$tableName] WHERE 1 = 0";
//CheckRowCount($conn1, $tsql1, 0);
$tsql2 = "SELECT id FROM [$tableName] WHERE id = 1";
CheckRowCount($conn1, $tsql2, -1);
$tsql3 = "INSERT INTO [$tableName] ($dataCols) VALUES (7, 'g')";
CheckRowCount($conn1, $tsql3, 1);
$tsql3 = "DELETE FROM [$tableName]";
CheckRowCount($conn1, $tsql3, 7);
// Cleanup
DropTable($conn1, $tableName);
$conn1 = null;
EndTest($testName);
}
function CheckRowCount($conn, $tsql, $rows)
{
$stmt = ExecuteQuery($conn, $tsql);
$count = $stmt->rowCount();
if ($count !== $rows)
{
printf("Unexpected row count: $count instead of $rows\n");
}
unset($stmt);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
RowCountTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Statement - Row Count" completed successfully.

View file

@ -0,0 +1,133 @@
--TEST--
PDO Fetch Mode Test
--DESCRIPTION--
Basic verification for "PDOStatement::setFetchMode()”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchMode()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Set Fetch Mode";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, grp";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'Group2'", null);
// Execute test
$tsql = "SELECT val, grp FROM [$tableName]";
$stmt1 = $conn1->query($tsql, PDO::FETCH_NUM);
var_dump($stmt1->fetchAll());
unset($stmt1);
$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test');
var_dump($stmt1->fetchAll());
unset($stmt1);
$stmt1 = $conn1->query($tsql, PDO::FETCH_NUM);
$stmt1->setFetchMode(PDO::FETCH_CLASS, 'Test', array('Changed'));
var_dump($stmt1->fetchAll());
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
function __construct($name = 'N/A')
{
echo __METHOD__ . "($name)\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchMode();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
array(2) {
[0]=>
array(2) {
[0]=>
string(1) "A"
[1]=>
string(6) "Group1"
}
[1]=>
array(2) {
[0]=>
string(1) "B"
[1]=>
string(6) "Group2"
}
}
Test::__construct(N/A)
Test::__construct(N/A)
array(2) {
[0]=>
object(Test)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
[1]=>
object(Test)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
string(6) "Group2"
}
}
Test::__construct(Changed)
Test::__construct(Changed)
array(2) {
[0]=>
object(Test)#%d (2) {
["val"]=>
string(1) "A"
["grp"]=>
string(6) "Group1"
}
[1]=>
object(Test)#%d (2) {
["val"]=>
string(1) "B"
["grp"]=>
string(6) "Group2"
}
}
Test "PDO Statement - Set Fetch Mode" completed successfully.

View file

@ -0,0 +1,273 @@
--TEST--
PDO Fetch Bound Test
--DESCRIPTION--
Verification for "PDOStatenent::fetch(PDO::FETCH_BOUND)".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch Bound";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'));
// Insert using question mark placeholders
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
// Count inserted rows
$stmt2 = PrepareQuery($conn1, "SELECT COUNT(id) FROM [$tableName]");
$stmt2->execute();
$num = $stmt2->fetchColumn();
echo 'There are ' . $num . " rows in the table.\n";
$stmt2->closeCursor();
// Insert using named parameters
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(:first, :second, :third)");
foreach ($data as $row)
{
$stmt1->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1], ':third'=>$row[2]));
}
unset($stmt1);
$stmt2->execute();
$num = $stmt2->fetchColumn();
echo 'There are ' . $num . " rows in the table.\n";
$dataCols = "idx, txt";
CreateTableEx($conn1, $tableName, "idx int NOT NULL PRIMARY KEY, txt VARCHAR(20)", null);
InsertRowEx($conn1, $tableName, $dataCols, "0, 'String0'", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'String1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'String2'", null);
// Testing with prepared query
$stmt1 = PrepareQuery($conn1, "SELECT COUNT(idx) FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchColumn());
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx");
$stmt1->execute();
$data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
var_dump($data);
echo "===WHILE===\n";
$stmt1->bindColumn('idx', $idx);
$stmt1->bindColumn('txt', $txt);
$stmt1->execute();
while ($stmt1->fetch(PDO::FETCH_BOUND))
{
var_dump(array($idx=>$txt));
}
echo "===ALONE===\n";
$stmt2 = PrepareQuery($conn1, "SELECT txt FROM [$tableName] WHERE idx=:inp");
$stmt2->bindParam(':inp', $idx); // by foreign name
$stmt3 = PrepareQuery($conn1, "SELECT idx FROM [$tableName] WHERE txt=:txt");
$stmt3->bindParam(':txt', $txt); // using same name
foreach($data as $idx => $txt)
{
var_dump(array($idx=>$txt));
var_dump($stmt2->execute());
if ($idx == 0)
{ // bindColumn()s after execute() has been called at least once
$stmt2->bindColumn('txt', $col1);
}
var_dump($stmt2->fetch(PDO::FETCH_BOUND));
$stmt2->closeCursor();
var_dump($stmt3->execute());
if ($idx == 0)
{ // bindColumn()s after execute() has been called at least once
$stmt3->bindColumn('idx', $col2);
}
var_dump($stmt3->fetch(PDO::FETCH_BOUND));
$stmt3->closeCursor();
var_dump(array($col2=>$col1));
}
echo "===REBIND/SAME===\n";
$stmt3->bindColumn('idx', $col1);
foreach($data as $idx => $txt)
{
var_dump(array($idx=>$txt));
var_dump($stmt2->execute());
var_dump($stmt2->fetch(PDO::FETCH_BOUND));
$stmt2->closeCursor();
var_dump($col1);
var_dump($stmt3->execute());
var_dump($stmt3->fetch(PDO::FETCH_BOUND));
$stmt3->closeCursor();
var_dump($col1);
}
echo "===REBIND/CONFLICT===\n";
$stmt1->bindColumn('idx', $col1);
$stmt1->bindColumn('txt', $col1);
$stmt1->execute();
while($stmt1->fetch(PDO::FETCH_BOUND))
{
var_dump($col1);
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$stmt2 = null;
$stmt3 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
There are 6 rows in the table.
There are 12 rows in the table.
string(1) "3"
array(3) {
[0]=>
string(7) "String0"
[1]=>
string(7) "String1"
[2]=>
string(7) "String2"
}
===WHILE===
array(1) {
[0]=>
string(7) "String0"
}
array(1) {
[1]=>
string(7) "String1"
}
array(1) {
[2]=>
string(7) "String2"
}
===ALONE===
array(1) {
[0]=>
string(7) "String0"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
[0]=>
string(7) "String0"
}
array(1) {
[1]=>
string(7) "String1"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
[1]=>
string(7) "String1"
}
array(1) {
[2]=>
string(7) "String2"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
[2]=>
string(7) "String2"
}
===REBIND/SAME===
array(1) {
[0]=>
string(7) "String0"
}
bool(true)
bool(true)
string(7) "String0"
bool(true)
bool(true)
string(1) "0"
array(1) {
[1]=>
string(7) "String1"
}
bool(true)
bool(true)
string(7) "String1"
bool(true)
bool(true)
string(1) "1"
array(1) {
[2]=>
string(7) "String2"
}
bool(true)
bool(true)
string(7) "String2"
bool(true)
bool(true)
string(1) "2"
===REBIND/CONFLICT===
string(7) "String0"
string(7) "String1"
string(7) "String2"
Test "PDO Statement - Fetch Bound" completed successfully.

View file

@ -0,0 +1,155 @@
--TEST--
PDO Fetch Test with FETCH_INTO mode
--DESCRIPTION--
Verification of fetch behavior with "PDO::FETCH_INTO" mode.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch Into";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'));
// Insert data using question mark placeholders
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
// Retrive data
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
echo "===SUCCESS===\n";
$stmt1->setFetchMode(PDO::FETCH_INTO, new Test);
$stmt1->execute();
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===FAIL===\n";
$stmt1->setFetchMode(PDO::FETCH_INTO, new Fail);
$stmt1->execute();
foreach($stmt1 as $obj)
{
var_dump($obj);
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
public $id, $val, $val2;
}
class Fail
{
protected $id;
public $val, $val2;
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
===SUCCESS===
object(Test)#%d (3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
object(Test)#%d (3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
object(Test)#%d (3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
object(Test)#%d (3) {
["id"]=>
string(2) "40"
["val"]=>
string(3) "Jkl"
["val2"]=>
string(3) "qpo"
}
object(Test)#%d (3) {
["id"]=>
string(2) "50"
["val"]=>
string(3) "Mno"
["val2"]=>
string(3) "nml"
}
object(Test)#%d (3) {
["id"]=>
string(2) "60"
["val"]=>
string(3) "Pqr"
["val2"]=>
string(3) "kji"
}
===FAIL===
Fatal error: Uncaught Error: Cannot access protected property Fail::$id in %sPDO39_FetchInto.php:%x
Stack trace:
#0 %sPDO39_FetchInto.php(%x): Fetch()
#1 %sPDO39_FetchInto.php(%x): Repro()
#2 {main}
thrown in %sPDO39_FetchInto.php on line %x

View file

@ -0,0 +1,67 @@
--TEST--
PDO Query Test with PDO::FETCH_LAZY
--DESCRIPTION--
Verification for "PDO::query() with PDO::FETCH_LAZY mode".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch Lazy";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, name";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, name VARCHAR(20)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'test1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'test2'", null);
// Testing with direct query
$stmt1 = $conn1->query("SELECT * FROM [$tableName]", PDO::FETCH_LAZY);
foreach ($stmt1 as $v)
{
echo "lazy: " . $v->id.$v->name."\n";
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
lazy: 1test1
lazy: 2test2
Test "PDO Statement - Fetch Lazy" completed successfully.

View file

@ -0,0 +1,86 @@
--TEST--
PDO Fetch Test with PDO::FETCH_ASSOC
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_ASSOC)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_ASSOC);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
array(2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,86 @@
--TEST--
PDO Fetch Test with PDO::FETCH_NUM
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_NUM)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(true, PDO::FETCH_NUM);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "A"
}
[1]=>
array(2) {
[0]=>
string(1) "2"
[1]=>
string(1) "B"
}
[2]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,98 @@
--TEST--
PDO Fetch Test with PDO::FETCH_BOTH
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_BOTH)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_BOTH);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(4) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["val"]=>
string(1) "A"
[1]=>
string(1) "A"
}
[1]=>
array(4) {
["id"]=>
string(1) "2"
[0]=>
string(1) "2"
["val"]=>
string(1) "B"
[1]=>
string(1) "B"
}
[2]=>
array(4) {
["id"]=>
string(1) "3"
[0]=>
string(1) "3"
["val"]=>
string(1) "C"
[1]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,86 @@
--TEST--
PDO Fetch Test with PDO::FETCH_OBJ
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_OBJ)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_OBJ);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
array(3) {
[0]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,114 @@
--TEST--
PDO Fetch Test with PDO::FETCH_GROUP
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_GROUP)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = PrepareQuery($conn1, "SELECT val, id FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_NUM|$fetchMode));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC|$fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(PDO::FETCH_GROUP);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(2) {
["A"]=>
array(2) {
[0]=>
array(1) {
[0]=>
string(1) "1"
}
[1]=>
array(1) {
[0]=>
string(1) "2"
}
}
["C"]=>
array(1) {
[0]=>
array(1) {
[0]=>
string(1) "3"
}
}
}
array(2) {
["A"]=>
array(2) {
[0]=>
array(1) {
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
["id"]=>
string(1) "2"
}
}
["C"]=>
array(1) {
[0]=>
array(1) {
["id"]=>
string(1) "3"
}
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,120 @@
--TEST--
PDO Fetch Test with PDO::FETCH_UNIQUE
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_UNIQUE)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id CHAR(1) NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "'A', 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "'B', 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "'C', 'C'", null);
// Test FetchAll(PDO::FETCH_UNIQUE) without conflict
$stmt1 = PrepareQuery($conn1, "SELECT id, val FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_NUM|PDO::FETCH_UNIQUE));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE));
unset($stmt1);
// Test FetchAll(PDO::FETCH_UNIQUE) with conflict
$stmt1 = ExecuteQuery($conn1, "SELECT val, id FROM [$tableName]");
var_dump($stmt1->fetchAll(PDO::FETCH_NUM|PDO::FETCH_UNIQUE));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
["A"]=>
array(1) {
[0]=>
string(1) "A"
}
["B"]=>
array(1) {
[0]=>
string(1) "A"
}
["C"]=>
array(1) {
[0]=>
string(1) "C"
}
}
array(3) {
["A"]=>
array(1) {
["val"]=>
string(1) "A"
}
["B"]=>
array(1) {
["val"]=>
string(1) "A"
}
["C"]=>
array(1) {
["val"]=>
string(1) "C"
}
}
array(2) {
["A"]=>
array(1) {
[0]=>
string(1) "B"
}
["C"]=>
array(1) {
[0]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,250 @@
--TEST--
PDO Fetch Test with PDO::FETCH_CLASSTYPE
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_CLASSTYPE)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test tables
$dataCols1 = "id, name";
$table1 = $tableName."1";
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, name VARCHAR(10) NOT NULL UNIQUE", null);
InsertRowEx($conn1, $table1, $dataCols1, "0, 'stdClass'", null);
InsertRowEx($conn1, $table1, $dataCols1, "1, 'Test1'", null);
InsertRowEx($conn1, $table1, $dataCols1, "2, 'Test2'", null);
$dataCols2 = "id, classtype, val";
$table2 = $tableName."2";
CreateTableEx($conn1, $table2, "id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10)", null);
InsertRowEx($conn1, $table2, $dataCols2, "1, 0, 'A'", null);
InsertRowEx($conn1, $table2, $dataCols2, "2, 1, 'B'", null);
InsertRowEx($conn1, $table2, $dataCols2, "3, 2, 'C'", null);
InsertRowEx($conn1, $table2, $dataCols2, "4, 3, 'D'", null);
$dataCols3 = "id, classtype, val, grp";
$table3 = $tableName."3";
CreateTableEx($conn1, $table3, "id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $table3, $dataCols3, "1, 0, 'A', 'Group1'", null);
InsertRowEx($conn1, $table3, $dataCols3, "2, 1, 'B', 'Group1'", null);
InsertRowEx($conn1, $table3, $dataCols3, "3, 2, 'C', 'Group2'", null);
InsertRowEx($conn1, $table3, $dataCols3, "4, 3, 'D', 'Group2'", null);
// Test fetchAll(PDO::FETCH_CLASSTYPE)
$stmt1 = PrepareQuery($conn1, "SELECT $table1.name, $table2.id AS id, $table2.val AS val FROM $table2 LEFT JOIN $table1 ON $table2.classtype=$table1.id");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_NUM));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE, 'Test3'));
unset($stmt1);
// Test fetchAll(PDO::FETCH_CLASSTYPE) with GROUP/UNIQUE
$stmt1 = PrepareQuery($conn1, "SELECT $table1.name, $table3.grp AS grp, $table3.id AS id, $table3.val AS val FROM $table3 LEFT JOIN $table1 ON $table3.classtype=$table1.id");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_GROUP, 'Test3'));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_UNIQUE, 'Test3'));
// Cleanup
DropTable($conn1, $table1);
DropTable($conn1, $table2);
DropTable($conn1, $table3);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test1
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test2
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test3
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
array(4) {
[0]=>
array(3) {
[0]=>
string(8) "stdClass"
[1]=>
string(1) "1"
[2]=>
string(1) "A"
}
[1]=>
array(3) {
[0]=>
string(5) "Test1"
[1]=>
string(1) "2"
[2]=>
string(1) "B"
}
[2]=>
array(3) {
[0]=>
string(5) "Test2"
[1]=>
string(1) "3"
[2]=>
string(1) "C"
}
[3]=>
array(3) {
[0]=>
NULL
[1]=>
string(1) "4"
[2]=>
string(1) "D"
}
}
Test1::__construct()
Test2::__construct()
Test3::__construct()
array(4) {
[0]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(Test2)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[3]=>
object(Test3)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
Test1::__construct()
Test2::__construct()
Test3::__construct()
array(2) {
["Group1"]=>
array(2) {
[0]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
}
["Group2"]=>
array(2) {
[0]=>
object(Test2)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[1]=>
object(Test3)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
}
Test1::__construct()
Test2::__construct()
Test3::__construct()
array(2) {
["Group1"]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
["Group2"]=>
object(Test3)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,138 @@
--TEST--
PDO Fetch Test with PDO::FETCH_COLUMN
--DESCRIPTION--
Verification for "PDOStatement::fetchAll(PDO::FETCH_COLUMN)".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'A2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'A', 'B2'", null);
// Testing with prepared query
$stmt1 = PrepareQuery($conn1, "SELECT id, val, val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN, 2));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 0));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 1));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 2));
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT val, val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
}
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
array(2) {
[1]=>
array(1) {
[0]=>
string(1) "A"
}
[2]=>
array(1) {
[0]=>
string(1) "A"
}
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(1) "1"
[2]=>
string(1) "2"
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(2) "A2"
[2]=>
string(2) "B2"
}
array(1) {
["A"]=>
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,141 @@
--TEST--
PDO Fetch Test with PDO::FETCH_COLUMN for unicode column names
--DESCRIPTION--
Verification for "PDOStatement::fetchAll(PDO::FETCH_COLUMN)".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$val = str_repeat("P银河系", 32);
$val2 = str_repeat("银河系мужирафиtest是", 8);
$dataCols = "id, $val, $val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, $val VARCHAR(10), $val2 VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'A2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'A', 'B2'", null);
// Testing with prepared query
$stmt1 = PrepareQuery($conn1, "SELECT id, $val, $val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN, 2));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 0));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 1));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 2));
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT $val, $val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
}
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
array(2) {
[1]=>
array(1) {
[0]=>
string(1) "A"
}
[2]=>
array(1) {
[0]=>
string(1) "A"
}
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(1) "1"
[2]=>
string(1) "2"
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(2) "A2"
[2]=>
string(2) "B2"
}
array(1) {
["A"]=>
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,340 @@
--TEST--
PDO Fetch Test with PDO::FETCH_FUNC
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_FUNC)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test tables
$dataCols = "id, val, grp";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C', 'Group2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'D', 'Group2'", null);
$f = new Test1(0, 0);
// Query table and retrieve data
$stmt1 = PrepareQuery($conn1, "SELECT grp, id FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC|PDO::FETCH_GROUP, 'test'));
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT id, val FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, 'test'));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array('Test1','factory')));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($f, 'factory')));
unset($stmt1);
$stmt1 = $conn1->prepare("SELECT id, val FROM [$tableName]",
array(PDO::ATTR_STATEMENT_CLASS=>array('DerivedStatement',
array('Overloaded', $conn1))));
var_dump(get_class($stmt1));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($stmt1, 'retrieve')));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($stmt1, 'reTrieve')));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($stmt1, 'RETRIEVE')));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class DerivedStatement extends PDOStatement
{
private function __construct($name, $conn)
{
$this->name = $name;
echo __METHOD__ . "($name)\n";
}
function reTrieve($id, $val) {
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
}
}
class Test1
{
public function __construct($id, $val)
{
echo __METHOD__ . "($id,$val)\n";
$this->id = $id;
$this->val = $val;
}
static public function factory($id, $val)
{
echo __METHOD__ . "($id,$val)\n";
return new self($id, $val);
}
}
function test($id,$val='N/A')
{
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Test1::__construct(0,0)
test(1,N/A)
test(2,N/A)
test(3,N/A)
test(4,N/A)
array(2) {
["Group1"]=>
array(2) {
[0]=>
array(1) {
[1]=>
string(3) "N/A"
}
[1]=>
array(1) {
[2]=>
string(3) "N/A"
}
}
["Group2"]=>
array(2) {
[0]=>
array(1) {
[3]=>
string(3) "N/A"
}
[1]=>
array(1) {
[4]=>
string(3) "N/A"
}
}
}
test(1,A)
test(2,B)
test(3,C)
test(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
Test1::factory(1,A)
Test1::__construct(1,A)
Test1::factory(2,B)
Test1::__construct(2,B)
Test1::factory(3,C)
Test1::__construct(3,C)
Test1::factory(4,D)
Test1::__construct(4,D)
array(4) {
[0]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[3]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
Test1::factory(1,A)
Test1::__construct(1,A)
Test1::factory(2,B)
Test1::__construct(2,B)
Test1::factory(3,C)
Test1::__construct(3,C)
Test1::factory(4,D)
Test1::__construct(4,D)
array(4) {
[0]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[3]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
DerivedStatement::__construct(Overloaded)
string(16) "DerivedStatement"
DerivedStatement::reTrieve(1,A)
DerivedStatement::reTrieve(2,B)
DerivedStatement::reTrieve(3,C)
DerivedStatement::reTrieve(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
DerivedStatement::reTrieve(1,A)
DerivedStatement::reTrieve(2,B)
DerivedStatement::reTrieve(3,C)
DerivedStatement::reTrieve(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
DerivedStatement::reTrieve(1,A)
DerivedStatement::reTrieve(2,B)
DerivedStatement::reTrieve(3,C)
DerivedStatement::reTrieve(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,130 @@
--TEST--
PDO Fetch Object Test
--DESCRIPTION--
Basic verification for "PDOStatement::fetchObject”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
class TestClass
{
private $set_calls = 0;
protected static $static_set_calls = 0;
// NOTE: PDO does not care about protected
protected $grp;
// NOTE: PDO does not care about private and calls __construct() after __set()
private function __construct($param1, $param2)
{
printf("TestClass::__construct(%s, %s): %d / %d\n", $param1, $param2,
self::$static_set_calls, $this->set_calls);
}
// NOTE: PDO will call __set() prior to calling __construct()
public function __set($prop, $value)
{
$this->inc();
printf("TestClass::__set(%s, -%s-) %d\n",
$prop, var_export($value, true), $this->set_calls, self::$static_set_calls);
$this->{$prop} = $value;
}
// NOTE: PDO can call regular methods prior to calling __construct()
public function inc()
{
$this->set_calls++;
self::$static_set_calls++;
}
}
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch Object";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
// Query test table and retrieve data
$tsql = "SELECT TOP(3) * FROM [$tableName] ORDER BY id ASC";
$stmt1 = PrepareQuery($conn1, $tsql);
$stmt1->execute();
$rowno = 0;
$rows[] = array();
while (is_object($rows[] = $stmt1->fetchObject('TestClass', array($rowno++, $rowno))))
{
printf("PDOStatement::fetchObject() was called for row $rowno\n");
}
var_dump($rows[$rowno - 1]);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
TestClass::__set(id, -'1'-) 1
TestClass::__set(label, -'a'-) 2
TestClass::__construct(0, 1): 2 / 2
PDOStatement::fetchObject() was called for row 1
TestClass::__set(id, -'2'-) 1
TestClass::__set(label, -'b'-) 2
TestClass::__construct(1, 2): 4 / 2
PDOStatement::fetchObject() was called for row 2
TestClass::__set(id, -'3'-) 1
TestClass::__set(label, -'c'-) 2
TestClass::__construct(2, 3): 6 / 2
PDOStatement::fetchObject() was called for row 3
object(TestClass)#%d (4) {
["set_calls":"TestClass":private]=>
int(2)
["grp":protected]=>
NULL
["id"]=>
string(1) "3"
["label"]=>
string(1) "c"
}
Test "PDO Statement - Fetch Object" completed successfully.

View file

@ -0,0 +1,123 @@
--TEST--
PDO Fetch LOB Test
--DESCRIPTION--
Verification for LOB handling.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function LobTest()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch LOB";
StartTest($testName);
$conn1 = Connect();
// Execute test
$data = str_repeat('A', 255);
FetchLob(1, $conn1, $tableName, "VARCHAR(512)", 1, $data);
FetchLob(2, $conn1, $tableName, "NVARCHAR(512)", 2, $data);
unset($data);
$data = str_repeat('B', 4000);
FetchLob(3, $conn1, $tableName, "VARCHAR(8000)", 3, $data);
FetchLob(4, $conn1, $tableName, "NVARCHAR(4000)", 4, $data);
unset($data);
$data = str_repeat('C', 100000);
FetchLob(5, $conn1, $tableName, "TEXT", 5, $data);
FetchLob(6, $conn1, $tableName, "NTEXT", 6, $data);
unset($data);
// Cleanup
DropTable($conn1, $tableName);
$conn1 = null;
EndTest($testName);
}
function FetchLob($offset, $conn, $table, $sqlType, $data1, $data2)
{
$id = NULL;
$label = NULL;
CreateTableEx($conn, $table, "id int NOT NULL PRIMARY KEY, label $sqlType", null);
InsertRowEx($conn, $table, "id, label", "$data1, '$data2'", null);
// Check data fetched with PDO::FETCH_BOUND
$stmt = ExecuteQuery($conn, "SELECT * FROM [$table]");
if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $label, PDO::PARAM_LOB))
{
LogInfo($offset, "Cannot bind LOB column");
}
if (!$stmt->fetch(PDO::FETCH_BOUND))
{
LogInfo($offset, "Cannot fetch bound data");
}
if ($id != $data1)
{
LogInfo($offset, "ID data corruption: [$id] instead of [$data1]");
}
if ($label != $data2)
{
LogInfo($offset, "Label data corruption: [$label] instead of [$data2]");
}
unset($stmt);
unset($label);
// Check data fetched with PDO::FETCH_ASSOC
$stmt = ExecuteQuery($conn, "SELECT * FROM [$table]");
$refData = $stmt->fetch(PDO::FETCH_ASSOC);
if ($refData['id'] != $data1)
{
$id = $refData['id'];
LogInfo($offset, "ID data corruption: [$id] instead of [$data1]");
}
if ($refData['label'] != $data2)
{
$label = $refData['label'];
LogInfo($offset, "Label data corruption: [$label] instead of [$data2]");
}
unset($stmt);
unset($refData);
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
LobTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Statement - Fetch LOB" completed successfully.

View file

@ -0,0 +1,163 @@
--TEST--
PDO Bind Column Test
--DESCRIPTION--
Verification for "PDOStatement::bindColumn".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Column";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "idx, txt";
CreateTableEx($conn1, $tableName, "idx int NOT NULL PRIMARY KEY, txt VARCHAR(20)", null);
InsertRowEx($conn1, $tableName, $dataCols, "0, 'String0'", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'String1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'String2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'String3'", null);
// Testing with prepared query
LogInfo(1, "Testing fetchColumn() ...");
$stmt1 = ExecuteQuery($conn1, "SELECT COUNT(idx) FROM [$tableName]");
var_dump($stmt1->fetchColumn());
unset($stmt1);
LogInfo(2, "Testing fetchAll() ...");
$stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx");
$stmt1->execute();
$data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
var_dump($data);
LogInfo(3, "Testing bindColumn() ...");
$stmt1->bindColumn('idx', $idx);
$stmt1->bindColumn('txt', $txt);
$stmt1->execute();
while ($stmt1->fetch(PDO::FETCH_BOUND))
{
var_dump(array($idx=>$txt));
}
LogInfo(4, "Testing bindColumn() with data check ...");
$id = null;
$val = null;
$data = array();
$index = 0;
if (!$stmt1->bindColumn(1, $id, PDO::PARAM_INT))
{
LogError(5, "Cannot bind integer column", $stmt1);
}
if (!$stmt1->bindColumn(2, $val, PDO::PARAM_STR))
{
LogError(5, "Cannot bind string column", $stmt1);
}
$stmt1->execute();
while ($stmt1->fetch(PDO::FETCH_BOUND))
{
$data[] = array('id' => $id, 'val' => $val);
printf("id = %s (%s) / val = %s (%s)\n",
var_export($id, true), gettype($id),
var_export($val, true), gettype($val));
}
unset($stmt1);
$stmt1 = ExecuteQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx");
while ($row = $stmt1->fetch(PDO::FETCH_ASSOC))
{
if ($row['idx'] != $data[$index]['id'])
{
LogInfo(6, "Data corruption for integer column in row $index");
}
if ($row['txt'] != $data[$index]['val'])
{
LogInfo(6, "Data corruption for string column in row $index");
}
$index++;
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
function LogError($offset, $msg, &$obj)
{
printf("[%03d] %s: %s\n", $offset, $msg, $obj->errorCode);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
[001] Testing fetchColumn() ...
string(1) "4"
[002] Testing fetchAll() ...
array(4) {
[0]=>
string(7) "String0"
[1]=>
string(7) "String1"
[2]=>
string(7) "String2"
[3]=>
string(7) "String3"
}
[003] Testing bindColumn() ...
array(1) {
[0]=>
string(7) "String0"
}
array(1) {
[1]=>
string(7) "String1"
}
array(1) {
[2]=>
string(7) "String2"
}
array(1) {
[3]=>
string(7) "String3"
}
[004] Testing bindColumn() with data check ...
id = 0 (integer) / val = 'String0' (string)
id = 1 (integer) / val = 'String1' (string)
id = 2 (integer) / val = 'String2' (string)
id = 3 (integer) / val = 'String3' (string)
Test "PDO Statement - Bind Column" completed successfully.

View file

@ -0,0 +1,133 @@
--TEST--
PDO Bind Column Test
--DESCRIPTION--
Verification for "PDOStatement::bindColumn()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Column";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
$rowCount = 3;
$midRow = 4;
// Check bind column
$tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName] ORDER BY id ASC";
$data = BindColumn($conn1, $tsql1);
CheckBind($conn1, $tsql1, $data);
$tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY id ASC) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow";
$data = BindColumn($conn1, $tsql2);
CheckBind($conn1, $tsql2, $data);
// Cleanup
DropTable($conn1, $tableName);
$conn1 = null;
EndTest($testName);
}
function BindColumn($conn, $tsql)
{
$id = null;
$label = null;
$data = array();
$stmt = PrepareQuery($conn, $tsql);
$stmt->execute();
if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT))
{
LogInfo(1, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR))
{
LogInfo(1, "Cannot bind string column");
}
while ($stmt->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / label = %s (%s)\n",
var_export($id, true), gettype($id),
var_export($label, true), gettype($label));
$data[] = array('id' => $id, 'label' => $label);
}
unset($stmt);
return ($data);
}
function CheckBind($conn, $tsql, $data)
{
$index = 0;
$stmt = ExecuteQuery($conn, $tsql);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if ($row['id'] != $data[$index]['id'])
{
LogInfo(2, "Fetch bound and fetch assoc differ - column 'id', row $index");
}
if ($row['label'] != $data[$index]['label'])
{
LogInfo(2, "Fetch bound and fetch assoc differ - column 'label', row $index");
}
$index++;
}
unset($stmt);
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
id = 3 (integer) / label = 'c' (string)
id = 4 (integer) / label = 'd' (string)
id = 5 (integer) / label = 'e' (string)
id = 6 (integer) / label = 'f' (string)
Test "PDO Statement - Bind Column" completed successfully.

View file

@ -0,0 +1,85 @@
--TEST--
PDO Bind Param Test
--DESCRIPTION--
Verification for "PDOStatement::bindParam()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Param";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, name";
CreateTableEx($conn1, $tableName, "id int, name VARCHAR(20)", null);
$conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" );
// Insert test data
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] ($dataCols) VALUES(0, :name)");
$name = NULL;
$before_bind = $name;
$stmt1->bindParam(':name', $name);
// Check that bindParam does not modify parameter
if ($name !== $before_bind)
{
echo "bind: fail\n";
}
else
{
echo "bind: success\n";
}
var_dump($stmt1->execute());
unset($stmt1);
// Retrieve test data
$stmt1 = ExecuteQuery($conn1, "SELECT name FROM [$tableName] WHERE id = 0");
var_dump($stmt1->fetchColumn());
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
bind: success
bool(true)
NULL
Test "PDO Statement - Bind Param" completed successfully.

View file

@ -0,0 +1,142 @@
--TEST--
PDO Bind Param Test
--DESCRIPTION--
Verification for "PDOStatement::bindParam()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Param";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
$id = null;
$label = null;
// Bind param @ SELECT
$tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC";
$value1 = 0;
$stmt1 = PrepareQuery($conn1, $tsql1);
BindParam(1, $stmt1, $value1);
ExecStmt(1, $stmt1);
BindColumn(1, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
ExecStmt(1, $stmt1);
FetchBound($stmt1, $id, $label);
unset($stmt1);
// Bind param @ INSERT
$tsql2 = "INSERT INTO [$tableName](id, label) VALUES (100, ?)";
$value2 = null;
$stmt1 = PrepareQuery($conn1, $tsql2);
BindParam(2, $stmt1, $value2);
ExecStmt(2, $stmt1);
unset($stmt1);
// Check binding
$tsql3 = "SELECT id, NULL AS _label FROM [$tableName] WHERE label IS NULL";
$stmt1 = ExecuteQuery($conn1, $tsql3);
BindColumn(3, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
unset($stmt1);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function BindParam($offset, $stmt, &$value)
{
if (!$stmt->bindParam(1, $value))
{
LogInfo($offset,"Cannot bind parameter");
}
}
function BindColumn($offset, $stmt, &$param1, &$param2)
{
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR))
{
LogInfo($offset, "Cannot bind string column");
}
}
function ExecStmt($offset, $stmt)
{
if (!$stmt->execute())
{
LogInfo($offset, "Cannot execute statement");
}
}
function FetchBound($stmt, &$param1, &$param2)
{
while ($stmt->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / label = %s (%s)\n",
var_export($param1, true), gettype($param1),
var_export($param2, true), gettype($param2));
}
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
id = 100 (integer) / label = NULL (NULL)
Test "PDO Statement - Bind Param" completed successfully.

View file

@ -0,0 +1,84 @@
--TEST--
PDO Bind Value Test
--DESCRIPTION--
Verification for "PDOStatement::bindValue()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Value";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10), val3 VARCHAR(10)", null);
$data = array("one", "two", "three");
// Insert test data
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(1, ?, ?, ?)");
foreach ($data as $i => $v)
{
$stmt1->bindValue($i+1, $v);
}
$stmt1->execute();
unset($stmt1);
// Retrieve test data
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(1) {
[0]=>
array(4) {
["id"]=>
string(1) "1"
["val1"]=>
string(3) "one"
["val2"]=>
string(3) "two"
["val3"]=>
string(5) "three"
}
}
Test "PDO Statement - Bind Value" completed successfully.

View file

@ -0,0 +1,203 @@
--TEST--
PDO Bind Value Test
--DESCRIPTION--
Verification for "PDOStatement::bindValue()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Value";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
$id = null;
$label = null;
// Check different value bind modes
$tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC";
$stmt1 = PrepareQuery($conn1, $tsql1);
printf("Binding value and not variable...\n");
BindValue(1, $stmt1, 0);
ExecStmt(1, $stmt1);
BindColumn(1, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
printf("Binding variable...\n");
$var1 = 0;
BindVar(2, $stmt1, $var1);
ExecStmt(2, $stmt1);
BindColumn(2, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
printf("Binding variable which references another variable...\n");
$var2 = 0;
$var_ref = &$var2;
BindVar(3, $stmt1, $var_ref);
ExecStmt(3, $stmt1);
BindColumn(3, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
unset($stmt1);
$tsql2 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? AND id <= ? ORDER BY id ASC";
$stmt1 = PrepareQuery($conn1, $tsql2);
printf("Binding a variable and a value...\n");
$var3 = 0;
BindMixed(4, $stmt1, $var3, 2);
ExecStmt(4, $stmt1);
BindColumn(4, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
printf("Binding a variable to two placeholders and changing the variable value in between the binds...\n");
$var4 = 0;
$var5 = 2;
BindPlaceholder(5, $stmt1, $var4, $var5);
ExecStmt(5, $stmt1);
BindColumn(5, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
unset($stmt1);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function BindValue($offset, $stmt, $value)
{
if (!$stmt->bindValue(1, $value))
{
LogInfo($offset, "Cannot bind value");
}
}
function BindVar($offset, $stmt, &$var)
{
if (!$stmt->bindValue(1, $var))
{
LogInfo($offset, "Cannot bind variable");
}
}
function BindMixed($offset, $stmt, &$var, $value)
{
if (!$stmt->bindValue(1, $var))
{
LogInfo($offset, "Cannot bind variable");
}
if (!$stmt->bindValue(2, $value))
{
LogInfo($offset, "Cannot bind value");
}
}
function BindPlaceholder($offset, $stmt, &$var1, &$var2)
{
if (!$stmt->bindValue(1, $var1))
{
LogInfo($offset, "Cannot bind variable 1");
}
if (!$stmt->bindValue(2, $var2))
{
LogInfo($offset, "Cannot bind variable 2");
}
}
function BindColumn($offset, $stmt, &$param1, &$param2)
{
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR))
{
LogInfo($offset, "Cannot bind string column");
}
}
function ExecStmt($offset, $stmt)
{
if (!$stmt->execute())
{
LogInfo($offset, "Cannot execute statement");
}
}
function FetchBound($stmt, &$param1, &$param2)
{
while ($stmt->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / label = %s (%s)\n",
var_export($param1, true), gettype($param1),
var_export($param2, true), gettype($param2));
}
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Binding value and not variable...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding variable...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding variable which references another variable...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding a variable and a value...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding a variable to two placeholders and changing the variable value in between the binds...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Test "PDO Statement - Bind Value" completed successfully.

View file

@ -0,0 +1,141 @@
--TEST--
PDO Bind Param Truncation Test
--DESCRIPTION--
Verification for "PDOStatement::bindParam()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Param Truncation";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id INT IDENTITY NOT NULL, class INT, value CHAR(32)", null);
$conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" );
$tsql1 = "SET IDENTITY_INSERT [$tableName] ON";
$tsql2 = "INSERT INTO [$tableName] (id, class, value) VALUES(:id, :class, :value)";
$tsql3 = "SET IDENTITY_INSERT [$tableName] OFF";
$tsql4 = "SELECT id, value FROM [$tableName]";
$id = 0;
$class = 0;
$value = '';
// Prepare insert query
$stmt1 = PrepareQuery($conn1, "$tsql1; $tsql2; $tsql3;");
BindParam(1, $stmt1, ':id', $id);
BindParam(2, $stmt1, ':class', $class);
BindParam(3, $stmt1, ':value', $value);
// Insert test rows
$id = 1;
$class = 4;
$value = '2011';
ExecStmt(1, $stmt1);
$id = 2;
$class = 5;
$value = 'Sat, 20 Mar 10 21:29:13 -0600';
ExecStmt(2, $stmt1);
$id = 3;
$class = 6;
$value = 'Fri, 07 May 10 11:35:32 -0600';
ExecStmt(3, $stmt1);
unset($stmt1);
$stmt1 = null;
// Check data
$id = 0;
$value = '';
$stmt2 = ExecuteQuery($conn1, $tsql4);
BindColumn(1, $stmt2, $id, $value);
while ($stmt2->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / value = %s (%s)\n",
var_export($id, true), gettype($id),
var_export($value, true), gettype($value));
}
unset($stmt2);
$stmt2 = null;
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function BindParam($offset, $stmt, $param, &$value)
{
if (!$stmt->bindParam($param, $value))
{
LogInfo($offset,"Cannot bind parameter $param");
}
}
function BindColumn($offset, $stmt, &$param1, &$param2)
{
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR))
{
LogInfo($offset, "Cannot bind string column");
}
}
function ExecStmt($offset, $stmt)
{
if (!$stmt->execute())
{
LogInfo($offset, "Cannot execute statement");
var_dump($stmt->errorInfo());
}
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
id = 1 (integer) / value = '2011 ' (string)
id = 2 (integer) / value = 'Sat, 20 Mar 10 21:29:13 -0600 ' (string)
id = 3 (integer) / value = 'Fri, 07 May 10 11:35:32 -0600 ' (string)
Test "PDO Statement - Bind Param Truncation" completed successfully.

View file

@ -0,0 +1,100 @@
--TEST--
PDO Transactions Test
--DESCRIPTION--
Basic verification for PDO Transactions.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Transactions()
{
include 'MsSetup.inc';
$testName = "PDO - Transactions";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// After INSERT ...
$count = countRows($conn1, $tableName);
echo "Rows after INSERT: $count.\n";
// Prepare DELETE query
$stmt1 = PrepareQuery($conn1, "DELETE FROM [$tableName]");
// Transaction -> Rollback
$conn1->beginTransaction();
$stmt1->execute();
$count = countRows($conn1, $tableName);
echo "Rows after DELETE: $count.\n";
$conn1->rollBack();
$count = countRows($conn1, $tableName);
echo "Rows after ROLLBACK: $count.\n";
// Transaction -> Commit
$conn1->beginTransaction();
$stmt1->execute();
$count = countRows($conn1, $tableName);
echo "Rows after DELETE: $count.\n";
$conn1->commit();
$count = countRows($conn1, $tableName);
echo "Rows after COMMIT: $count.\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function countRows($conn, $table)
{
$stmt = ExecuteQuery($conn, "SELECT COUNT(*) FROM [$table]");
$res = $stmt->fetchColumn();
unset($stmt);
return ($res);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Transactions();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Rows after INSERT: 3.
Rows after DELETE: 0.
Rows after ROLLBACK: 3.
Rows after DELETE: 0.
Rows after COMMIT: 0.
Test "PDO - Transactions" completed successfully.

View file

@ -0,0 +1,95 @@
--TEST--
PDO Transactions Test
--DESCRIPTION--
Basic verification for PDO Transactions.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Transactions()
{
include 'MsSetup.inc';
$testName = "PDO - Transactions";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// After initial INSERT ...
$count = countRows($conn1, $tableName);
echo "Rows after INSERT: $count.\n";
// Transaction -> Automatic rollback on disconnect
$conn1->beginTransaction();
InsertRowEx($conn1, $tableName, $dataCols, "4, 'X'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'Y'", null);
$conn1 = null; // disconnect without commit
$conn1 = Connect();
$count = countRows($conn1, $tableName);
echo "Rows after ROLLBACK: $count.\n";
// Transaction -> Commit
$conn1->beginTransaction();
InsertRowEx($conn1, $tableName, $dataCols, "4, 'D'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'E'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'F'", null);
$conn1->commit();
$count = countRows($conn1, $tableName);
echo "Rows after COMMIT: $count.\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function countRows($conn, $table)
{
$stmt = ExecuteQuery($conn, "SELECT COUNT(*) FROM [$table]");
$res = $stmt->fetchColumn();
unset($stmt);
return ($res);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Transactions();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Rows after INSERT: 3.
Rows after ROLLBACK: 3.
Rows after COMMIT: 6.
Test "PDO - Transactions" completed successfully.

View file

@ -0,0 +1,82 @@
--TEST--
Complex Insert Query Test
--DESCRIPTION--
Test the driver behavior with a complex insert query.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ComplexInsert($count)
{
include 'MsSetup.inc';
$testName = "PDO - Complex Insert Query";
StartTest($testName);
Setup();
$conn1 = Connect();
DropTable($conn1, $tableName);
// $data = "a1='1234567890',a2='0987654321',a3='1234567890',a4='0987654321',a5='1234567890',a6='0987654321'";
$data = "a1='1', a2='2', a3='3', a4='4', a5='5', a6='6'";
$querySelect = "SELECT COUNT(*) FROM [$tableName]";
$queryInsert =
" SELECT $data INTO [$tableName]
DECLARE @i int
SET @i=1
WHILE (@i < $count)
BEGIN
INSERT [$tableName]
SELECT $data
SET @i = @i + 1
END
";
$stmt1 = ExecuteQuery($conn1, $queryInsert);
$stmt1->closeCursor();
$stmt1 = null;
$stmt2 = ExecuteQuery($conn1, $querySelect);
$row = $stmt2->fetch(PDO::FETCH_NUM);
printf("$count rows attempted; actual rows created = ".$row[0]."\n");
$stmt2 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ComplexInsert(1000);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
1000 rows attempted; actual rows created = 1000
Test "PDO - Complex Insert Query" completed successfully.

View file

@ -0,0 +1,68 @@
--TEST--
PDO Get Parent Class Test
--DESCRIPTION--
Verification for "get_parent_class()" functionality.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecTest()
{
include 'MsSetup.inc';
$testName = "PDO - Get Parent";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int", null);
$conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" );
InsertRowEx($conn1, $tableName, "id", "23", null);
// Retrieve data
$stmt1 = PrepareQuery($conn1, "SELECT id FROM [$tableName]");
$stmt1->execute();
$result = $stmt1->fetch(PDO::FETCH_LAZY);
// Retrieve class and parent
echo get_class($result), "\n";
var_dump(get_parent_class($result));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
PDORow
bool(false)
Test "PDO - Get Parent" completed successfully.

View file

@ -0,0 +1,118 @@
--TEST--
PDO Statement Iterator Test
--DESCRIPTION--
Verification of PDOStatement with an iterator.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Iterator";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, grp";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'Group2'", null);
$tsql = "SELECT val, grp FROM [$tableName]";
// Testing with direct query
/*$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test', array('WOW'));
$iter = new IteratorIterator($stmt1);
foreach ($iter as $data)
{
var_dump($data);
}
$iter->next(); // allowed
var_dump($iter->current()); // should return NULL
var_dump($iter->valid());*/ // should must return
unset($stmt1);
// Testing with prepared query
$stmt1 = $conn1->prepare($tsql, array(PDO::ATTR_STATEMENT_CLASS=>array('PDOStatementAggregate')));
foreach ($stmt1 as $data)
{
var_dump($data);
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
function __construct($name = 'N/A')
{
echo __METHOD__ . "($name)\n";
}
}
class PDOStatementAggregate extends PDOStatement implements IteratorAggregate
{
private function __construct()
{
echo __METHOD__ . "\n";
$this->setFetchMode(PDO::FETCH_NUM);
}
function getIterator()
{
echo __METHOD__ . "\n";
$this->execute();
return (new IteratorIterator($this, 'PDOStatement'));
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
PDOStatementAggregate::__construct
PDOStatementAggregate::getIterator
array(2) {
[0]=>
string(1) "A"
[1]=>
string(6) "Group1"
}
array(2) {
[0]=>
string(1) "B"
[1]=>
string(6) "Group2"
}
Test "PDO Statement - Iterator" completed successfully.

View file

@ -0,0 +1,116 @@
--TEST--
PDO Recursive Iterator Test
--DESCRIPTION--
Verification of PDOStatement with a recursive iterator.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Recursive Iterator";
StartTest($testName);
$conn1 = Connect();
// Prepare test tables
$dataCols = "id, val, val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
// Insert using question mark placeholders
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
echo "===QUERY===\n";
$stmt1 = ExecuteQuery($conn1, "SELECT * FROM [$tableName]");
foreach(new RecursiveTreeIterator(new RecursiveArrayIterator($stmt1->fetchAll(PDO::FETCH_ASSOC)),
RecursiveTreeIterator::BYPASS_KEY) as $c=>$v)
{
echo "$v [$c]\n";
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
function __construct($name = 'N/A')
{
echo __METHOD__ . "($name)\n";
}
}
class PDOStatementAggregate extends PDOStatement implements IteratorAggregate
{
private function __construct()
{
echo __METHOD__ . "\n";
$this->setFetchMode(PDO::FETCH_NUM);
}
function getIterator()
{
echo __METHOD__ . "\n";
$this->execute();
return (new IteratorIterator($this, 'PDOStatement'));
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
===QUERY===
|-Array [0]
| |-10 [id]
| |-Abc [val]
| \-zxy [val2]
|-Array [1]
| |-20 [id]
| |-Def [val]
| \-wvu [val2]
\-Array [2]
|-30 [id]
|-Ghi [val]
\-tsr [val2]
===DONE===
Test "PDO Statement - Recursive Iterator" completed successfully.

View file

@ -0,0 +1,133 @@
--TEST--
Extending PDO Test #1
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
$conn1->test();
var_dump($conn1);
// Prepare test table
DropTable($conn1, $tableName);
$conn1->query("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10))");
$conn1->query("INSERT INTO [$tableName] VALUES(0, 'A')");
$conn1->query("INSERT INTO [$tableName] VALUES(1, 'B')");
// Retrieve test data via a direct query
$stmt1 = ExecuteQuery($conn1, "SELECT val, id FROM [$tableName]");
$result = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
var_dump($result);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
public $test1 = 1;
function __destruct()
{
echo __METHOD__ . "()\n";
}
function test()
{
$this->test2 = 2;
var_dump($this->test1);
var_dump($this->test2);
$this->test2 = 22;
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = parent::prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('ExPDOStatement')));
$stmt->execute();
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
protected function __construct()
{
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
int(1)
int(2)
object(ExPDO)#%d (2) {
["test1"]=>
int(1)
["test2"]=>
int(22)
}
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::__destruct()
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::__destruct()
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::__destruct()
ExPDO::query()
ExPDOStatement::__construct()
array(2) {
["A"]=>
string(1) "0"
["B"]=>
string(1) "1"
}
ExPDOStatement::__destruct()
ExPDO::__destruct()
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,131 @@
--TEST--
Extending PDO Test #1
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
// simply use $databaseName from MsSetup.inc to facilitate testing in Azure,
// which does not support switching databases
$conn2 = new ExPDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd);
DropTable($conn2, "tmp_table");
$conn2->exec("CREATE TABLE tmp_table (id INT)");
$conn2->exec("INSERT INTO tmp_table (id) VALUES (1), (2)");
$stmt1 = $conn2->query("SELECT * FROM tmp_table ORDER BY id ASC");
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
var_dump($stmt1->fetch());
$conn2->intercept_call();
// Cleanup
DropTable($conn2, "tmp_table");
$stmt1 = null;
$conn2 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
public function __construct()
{
$this->protocol();
$args = func_get_args();
return (call_user_func_array(array($this, 'parent::__construct'), $args));
}
public function exec($args1)
{
$this->protocol();
$args = func_get_args();
return (call_user_func_array(array($this, 'parent::exec'), $args));
}
public function query()
{
$this->protocol();
$args = func_get_args();
return (call_user_func_array(array($this, 'parent::query'), $args));
}
public function __call($method, $args)
{
print "__call(".var_export($method, true).", ".var_export($args, true).")\n";
}
private function protocol()
{
$stack = debug_backtrace();
if (!isset($stack[1]))
{
return;
}
printf("%s(", $stack[1]['function']);
$args = '';
foreach ($stack[1]['args'] as $k => $v)
{
$args .= sprintf("%s, ", var_export($v, true));
}
if ($args != '')
{
printf("%s", substr($args, 0, -2));
}
printf(")\n");
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
__construct('%s', '%s', '%s')
exec('DROP TABLE %s')
exec('CREATE TABLE %s (id INT)')
exec('INSERT INTO %s (id) VALUES (1), (2)')
query('SELECT * FROM %s ORDER BY id ASC')
array(2) {
[0]=>
array(1) {
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
["id"]=>
string(1) "2"
}
}
bool(false)
__call('intercept_call', array (
))
exec('DROP TABLE %s')
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,145 @@
--TEST--
Extending PDO Test #2
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
var_dump(get_class($conn1));
// Prepare test table
DropTable($conn1, $tableName);
$conn1->exec("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))");
$stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)");
var_dump(get_class($stmt1));
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
// Retrieve test data via a direct query
$stmt1 = $conn1->query("SELECT * FROM [$tableName]");
var_dump(get_class($stmt1));
var_dump(get_class($stmt1->dbh));
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = $this->prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('ExPDOStatement', array($this))));
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
string(5) "ExPDO"
string(12) "PDOStatement"
ExPDO::query()
ExPDOStatement::__construct()
string(14) "ExPDOStatement"
string(5) "ExPDO"
array(3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
array(3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
array(3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
===DONE===
ExPDOStatement::__destruct()
ExPDO::__destruct()
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,159 @@
--TEST--
Extending PDO Test #3
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
var_dump(get_class($conn1));
// Prepare test table
DropTable($conn1, $tableName);
$conn1->exec("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))");
$stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)");
var_dump(get_class($stmt1));
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
echo "===QUERY===\n";
// Retrieve test data via a direct query
$stmt1 = $conn1->query("SELECT * FROM [$tableName]");
var_dump(get_class($stmt1));
var_dump(get_class($stmt1->dbh));
echo "===FOREACH===\n";
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = $this->prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('ExPDOStatement', array($this))));
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
function execute($params = array())
{
echo __METHOD__ . "()\n";
parent::execute();
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
string(5) "ExPDO"
string(12) "PDOStatement"
===QUERY===
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::execute()
string(14) "ExPDOStatement"
string(5) "ExPDO"
===FOREACH===
array(3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
array(3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
array(3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
===DONE===
ExPDOStatement::__destruct()
ExPDO::__destruct()
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,174 @@
--TEST--
Extending PDO Test #4
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
var_dump(get_class($conn1));
// Prepare test table
DropTable($conn1, $tableName);
$conn1->exec("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))");
$stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)");
var_dump(get_class($stmt1));
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
echo "===QUERY===\n";
// Retrieve test data via a direct query
var_dump($conn1->getAttribute(PDO::ATTR_STATEMENT_CLASS));
$conn1->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('ExPDOStatement', array($conn1)));
var_dump($conn1->getAttribute(PDO::ATTR_STATEMENT_CLASS));
$stmt1 = $conn1->query("SELECT * FROM [$tableName]");
var_dump(get_class($stmt1));
var_dump(get_class($stmt1->dbh));
echo "===FOREACH===\n";
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = parent::query($sql);
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
$this->setFetchMode(PDO::FETCH_ASSOC);
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
function execute($params = array())
{
echo __METHOD__ . "()\n";
parent::execute();
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
string(5) "ExPDO"
string(12) "PDOStatement"
===QUERY===
array(1) {
[0]=>
string(12) "PDOStatement"
}
array(2) {
[0]=>
string(14) "ExPDOStatement"
[1]=>
array(1) {
[0]=>
object(ExPDO)#%d (0) {
}
}
}
ExPDO::query()
ExPDOStatement::__construct()
string(14) "ExPDOStatement"
string(5) "ExPDO"
===FOREACH===
array(3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
array(3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
array(3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
===DONE===
ExPDOStatement::__destruct()
Test "PDO - Extension" completed successfully.
ExPDO::__destruct()

View file

@ -0,0 +1,64 @@
--TEST--
PDO - Quote Null Terminator
--DESCRIPTION--
Verifies the functionality of PDO::Quote, ensuring that the returned string
length does not include the null-terminator.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function QuoteTest()
{
include 'MsSetup.inc';
$testName = "PDO - Quote Null Terminator";
StartTest($testName);
Setup();
$testString = "This is a test string";
$expectedString = "'This is a test string'ASDF";
$conn = Connect();
$returnString = $conn->Quote($testString) . "ASDF";
if ($returnString !== $expectedString)
{
echo "Test String: $testString\nExpected String: $expectedString\nQuoted String: $returnString\n";
FatalError("Possible Regression: Quoted string may have null-terminator");
}
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
QuoteTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - Quote Null Terminator" completed successfully.

View file

@ -4,7 +4,7 @@ PDO Connection Pooling Test on Unix
This test assumes odbcinst.ini has not been modified.
This test also requires root privileges to modify odbcinst.ini file on Linux.
--SKIPIF--
<?php if(PHP_OS === "WINNT") die("Skipped: Test for Linux and Mac");
<?php if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') die("Skipped: Test for Linux and Mac");
--FILE--
<?php
$lines_to_add="CPTimeout=5\n[ODBC]\nPooling=Yes\n";

View file

@ -1,16 +0,0 @@
<?php
// Set SQL server + user + password
$serverName = getenv('MSSQL_SERVERNAME') ?: "localhost";
$username = getenv('MSSQL_USERNAME') ?: "sa";
$password = getenv('MSSQL_PASSWORD') ?: "<YourStrong!Passw0rd>";
// Generate unique DB name, example: php_20160817_1471475608267
$dbName = "php_" . date("Ymd") . "_" . round(microtime(true)*1000);
// Generic table name example: php_20160817_1471475608267.dbo.php_firefly
$tableName = $dbName.".dbo.php_firefly";
// Connection options
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password");
?>

View file

@ -1,10 +1,10 @@
<?php
include_once 'autonomous_setup.php';
$conn1 = new PDO("sqlsrv:Server=$serverName", $username, $password);
include 'MsSetup.inc';
$conn1 = new PDO("sqlsrv:Server=$server", $uid, $pwd);
$connId1 = ConnectionID($conn1);
$conn1 = null;
$conn2 = new PDO("sqlsrv:Server=$serverName", $username, $password);
$conn2 = new PDO("sqlsrv:Server=$server", $uid, $pwd);
$connId2 = ConnectionID($conn2);
if ($connId1 === $connId2){
@ -15,11 +15,11 @@ if ($connId1 === $connId2){
function ConnectionID($conn)
{
$tsql = "SELECT [connection_id] FROM [sys].[dm_exec_connections] where session_id = @@SPID";
$stmt = $conn->query($tsql);
$connID = $stmt->fetchColumn(0);
$stmt->closeCursor();
$stmt = null;
return ($connID);
$tsql = "SELECT [connection_id] FROM [sys].[dm_exec_connections] where session_id = @@SPID";
$stmt = $conn->query($tsql);
$connID = $stmt->fetchColumn(0);
$stmt->closeCursor();
$stmt = null;
return ($connID);
}
?>

View file

@ -0,0 +1,128 @@
--TEST--
verify github issue52 is fixed.
--DESCRIPTION--
This test only works in previous versions of SQL Servers. Full-text search features are
deprecated starting in SQL Server 2016.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
require_once 'MsSetup.inc';
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
#=================check SQL Server version===============
$attr = $conn->getAttribute(constant('PDO::ATTR_SERVER_VERSION'));
$version = substr($attr, 0, 2);
if ($version >= 13)
{
echo "Full-text search feature deprecated.\n";
return;
}
#=================run the test===========================
$tableName = 'test_Fulltext';
$dataType = 'Pagename varchar(20) not null primary key,URL varchar(30) not null,Description text null,Keywords varchar(4000) null';
if($conn)
{
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connection established.<br/>";
CreateTableEx($conn, $tableName, $dataType);
PopulateTable($conn,$tableName);
EnableFullText($conn, $tableName);
checkActiveTransactions($conn);
sleep(5);
FetchData($conn, $tableName);
DisableFullText($conn,$tableName);
FetchData($conn,$tableName);
}
else
{
echo "Connection could not be established.\n";
}
#=======================================================
function FetchData($conn,$tableName){
$query = "SELECT * FROM $tableName WHERE freetext(description,'Magazine')";
$stmt = $conn->query($query);
if(!$stmt)
{
var_dump($conn->errorInfo());
die( "PDOConn->query failed");
}
$stmt->bindColumn('Pagename',$Pagename);
$stmt->bindColumn('URL',$URL);
$stmt->bindColumn('Description',$Description);
$stmt->bindColumn('Keywords',$Keywords);
$result = $stmt->fetch(PDO::FETCH_BOUND);
if(!$result)
{
die("Fetch failed");
}
echo $Pagename . "\n";
echo $URL . "\n";
echo $Description . "\n";
}
#creating dummy data
function PopulateTable($conn,$tableName){
$dataCols = 'Pagename,URL,Description,Keywords';
$row1 = "'home.asp','home.asp','This is the home page','home,SQL'";
$row2 = "'PAGETWO.asp','/page2/pagetwo.asp','NT Magazine is great','second'";
$row3 = "'pagethree.asp','/page3/pagethree.asp','SQL Magazine is the greatest','third'";
$dataValues = array($row1, $row2, $row3);
foreach($dataValues as $value)
{
InsertRowEx($conn, $tableName, $dataCols, $value, null);
}
}
function EnableFullText($conn,$tableName){
echo "Enabling full-text index ... ";
$catalogName = "fulltext_".$tableName."_catalog";
#if the fulltext catalog exists, drop it;
dropCatalog($conn, $catalogName);
$query = "CREATE UNIQUE INDEX ui_ukJobCand ON $tableName(Pagename); CREATE FULLTEXT CATALOG $catalogName as default; CREATE FULLTEXT INDEX ON $tableName(URL, Description, Keywords) KEY INDEX ui_ukJobCand with stoplist = SYSTEM";
$outcome = $conn->exec($query);
if($outcome === false){
die("Failed to enable FULLTEXT INDEX on $tableName");
}
echo "completed successfully.\n";
}
function DisableFullText($conn,$tableName){
echo "\n Disabling full-text index ... ";
$query = "DROP FULLTEXT INDEX ON $tableName";
$outcome = $conn->exec($query);
if($outcome === false){
die("Failed to drop the FULLTEXT INDEX on $tableName");
}
echo "completed successfully.\n";
}
#=====================helpers==========================
function dropCatalog($conn, $catalogName){
$catalogExists="IF EXISTS (SELECT 1 FROM sys.fulltext_catalogs WHERE [name] = '$catalogName')
DROP FULLTEXT CATALOG $catalogName";
$outcome = $conn->exec($catalogExists);
if($outcome === false){
die("Failed to drop the $catalogName");
}
}
function checkActiveTransactions($conn){
$isActive = $conn->inTransaction();
if(!$isActive){
echo "No active transactions within the driver.\n";
}else{
echo "A transaction is currently active.\n";
}
}
?>
--EXPECTREGEX--
(Full-text search feature deprecated.|.*Connection established(.*Magazine.*)*
.*Disabling full-text index ... completed successfully..*
.*["message"].*Cannot use a CONTAINS or FREETEXT predicate on table or indexed view.* not full-text indexed.*)

View file

@ -1,13 +1,13 @@
--TEST--
Tests error returned when binding input/output parameter with emulate prepare
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
$database = 'tempdb';
$dsn = "sqlsrv:Server=$serverName ; Database = $database";
require_once("MsSetup.inc");
$dsn = "sqlsrv:Server=$server ; Database = $databaseName";
try {
$dbh = new PDO($dsn, $username, $password);
$dbh = new PDO($dsn, $uid, $pwd);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->query("IF OBJECT_ID('sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE sp_ReverseString");

View file

@ -1,47 +1,47 @@
--TEST--
Tests error returned when binding output parameter with emulate prepare
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require("MsSetup.inc");
$database = "tempdb";
$dsn = "sqlsrv:Server=$serverName ; Database = $database";
$dsn = "sqlsrv:Server=$server ; Database = $databaseName";
try {
$conn = new PDO($dsn, $username, $password);
$conn = new PDO($dsn, $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$count = 0;
$query = "select ? = count(* ) from cd_info";
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam( 1, $count, PDO::PARAM_STR, 10 );
$stmt->execute();
echo "Result: ".$count."\n";
$query = "select bigint_type, int_type, money_type from [test_types] where int_type < 0";
$stmt1 = $conn->prepare($query);
$stmt1->execute();
$row = $stmt1->fetch( PDO::FETCH_ASSOC );
print_r($row);
$query = "select ? = count(* ) from cd_info";
$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt->bindParam( 1, $count, PDO::PARAM_STR, 10 );
$stmt->execute();
echo "Result: ".$count."\n";
$query = "select bigint_type, int_type, money_type from [test_types] where int_type < 0";
$stmt1 = $conn->prepare($query);
$stmt1->execute();
$row = $stmt1->fetch( PDO::FETCH_ASSOC );
print_r($row);
$int = 0;
$bigint = 100;
$query = "select ? = bigint_type, ? = int_type, ? = money_type from [test_types] where int_type < 0";
$stmt2 = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt2->bindparam( 1, $bigint, PDO::PARAM_STR, 256 );
$stmt2->bindParam( 2, $int, PDO::PARAM_INT, 4 );
$stmt2->bindParam( 3, $money, PDO::PARAM_STR, 1024 );
$stmt2->execute();
echo "Big integer: ".$bigint."\n";
echo "Integer: ".$int."\n";
echo "Money: ".$money."\n";
//free the statement and connection
$stmt = null;
$stmt1 = null;
$stmt2 = null;
$conn = null;
$int = 0;
$bigint = 100;
$query = "select ? = bigint_type, ? = int_type, ? = money_type from [test_types] where int_type < 0";
$stmt2 = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true));
$stmt2->bindparam( 1, $bigint, PDO::PARAM_STR, 256 );
$stmt2->bindParam( 2, $int, PDO::PARAM_INT, 4 );
$stmt2->bindParam( 3, $money, PDO::PARAM_STR, 1024 );
$stmt2->execute();
echo "Big integer: ".$bigint."\n";
echo "Integer: ".$int."\n";
echo "Money: ".$money."\n";
//free the statement and connection
$stmt = null;
$stmt1 = null;
$stmt2 = null;
$conn = null;
}
catch(PDOException $e) {

View file

@ -1,14 +1,15 @@
--TEST--
Connection option APP name unicode
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$appName = "APP_PoP_银河";
// Connect
$conn = new PDO("sqlsrv:server=$serverName;APP=$appName","$username","$password");
$conn = new PDO("sqlsrv:server=$server;APP=$appName","$uid","$pwd");
// Query and Fetch
$query = "SELECT APP_NAME()";

View file

@ -1,23 +1,21 @@
--TEST--
Insert with quoted parameters
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO( "sqlsrv:server=$serverName", "$username", "$password" );
$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", "$uid", "$pwd" );
$param = 'a \' g';
$param2 = $conn->quote( $param );
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
// Create table
$query = "CREATE TABLE ".$tableName." (col1 VARCHAR(10), col2 VARCHAR(20))";
$stmt = $conn->query($query);
// Create a temporary table
$tableName = '#tmpTable';
$query = "CREATE TABLE $tableName (col1 VARCHAR(10), col2 VARCHAR(20))";
$stmt = $conn->exec($query);
if( $stmt === false ) { die(); }
// Inserd data
@ -42,9 +40,6 @@ $query = "delete from $tableName where col1 = ?";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param));
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
//free the statement and connection
$stmt=null;
$conn=null;

View file

@ -1,15 +1,12 @@
--TEST--
uses an input/output parameter
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$dbh = new PDO( "sqlsrv:server=$serverName", "$username", "$password" );
// CREATE database
$dbh->query("CREATE DATABASE ". $dbName) ?: die();
$dbh = new PDO( "sqlsrv:server=$server; database=$databaseName", "$uid", "$pwd" );
$dbh->query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString");
$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
@ -19,9 +16,6 @@ $stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
$stmt->execute();
print "Result: ".$string."\n"; // Expect 987654321
// DROP database
$dbh->query("DROP DATABASE ". $dbName) ?: die();
//free the statement and connection
$stmt = null;
$dbh = null;

View file

@ -1,49 +1,45 @@
--TEST--
Number of rows in a result set
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$conn = new PDO( "sqlsrv:server=$serverName", "$username", "$password" );
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", "$uid", "$pwd" );
// Create table
$stmt = $conn->query("CREATE TABLE ".$tableName." (c1 VARCHAR(32))");
$tableName = '#tmpTable1';
$stmt = $conn->exec("CREATE TABLE $tableName (c1 VARCHAR(32))");
$stmt=null;
// Insert data
$query = "INSERT INTO ".$tableName." VALUES ('Salmon'),('Butterfish'),('Cod'),('NULL'),('Crab')";
$query = "INSERT INTO $tableName VALUES ('Salmon'),('Butterfish'),('Cod'),('NULL'),('Crab')";
$stmt = $conn->query($query);
$res[] = $stmt->rowCount();
// Update data
$query = "UPDATE ".$tableName." SET c1='Salmon' WHERE c1='Cod'";
$query = "UPDATE $tableName SET c1='Salmon' WHERE c1='Cod'";
$stmt = $conn->query($query);
$res[] = $stmt->rowCount();
// Update data
$query = "UPDATE ".$tableName." SET c1='Salmon' WHERE c1='NULL'";
$query = "UPDATE $tableName SET c1='Salmon' WHERE c1='NULL'";
$stmt = $conn->query($query);
$res[] = $stmt->rowCount();
// Update data
$query = "UPDATE ".$tableName." SET c1='Salmon' WHERE c1='NO_NAME'";
$query = "UPDATE $tableName SET c1='Salmon' WHERE c1='NO_NAME'";
$stmt = $conn->query($query);
$res[] = $stmt->rowCount();
// Update data
$query = "UPDATE ".$tableName." SET c1='N/A'";
$query = "UPDATE $tableName SET c1='N/A'";
$stmt = $conn->query($query);
$res[] = $stmt->rowCount();
print_r($res);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
$stmt=null;
$conn=null;
print "Done"

View file

@ -1,23 +1,22 @@
--TEST--
Number MAX_INT to string with custom formats
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
/* Sample number MAX_INT */
$sample = 2*(2**30-1)+1;
var_dump ($sample);
/* Connect */
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// Create database
$conn->query("CREATE DATABASE $dbName") ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Create table
$tableName = '#testCustomFormats';
$query = "CREATE TABLE $tableName (col1 INT)";
$stmt = $conn->query($query);
$stmt = $conn->exec($query);
// Query number with custom format
$query ="SELECT CAST($sample as varchar) + '.00'";
@ -33,15 +32,11 @@ $stmt->execute();
// Fetching. Prepare with client buffered cursor
$query = "SELECT TOP 1 cast(col1 as varchar) + '.00 EUR' FROM $tableName";
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL,
PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
//Free the statement and connection
$stmt = null;
$conn = null;

View file

@ -1,9 +1,10 @@
--TEST--
Number MAX_INT to string with custom formats, see pdo_014. Pooling enabled.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$pooling = true;
@ -11,19 +12,17 @@ $pooling = true;
$sample = 2*(2**30-1)+1;
/* Connect + create a new pool */
$conn0 = new PDO("sqlsrv:server=$serverName;ConnectionPooling=$pooling", $username, $password);
$conn0 = new PDO("sqlsrv:server=$server;database=$databaseName;ConnectionPooling=$pooling", $uid, $pwd);
$conn0->query("select 1");
$conn0 = null;
/* Connect */
$conn = new PDO("sqlsrv:server=$serverName;ConnectionPooling=$pooling", $username, $password);
$conn = new PDO("sqlsrv:server=$server;database=$databaseName;ConnectionPooling=$pooling", $uid, $pwd);
// Create database
$conn->query("CREATE DATABASE $dbName") ?: die();
// Create table
// Create a temporary table
$tableName = '#testFormats';
$query = "CREATE TABLE $tableName (col1 INT)";
$stmt = $conn->query($query);
$stmt = $conn->exec($query);
// Query number with custom format
$query ="SELECT CAST($sample as varchar) + '.00'";
@ -39,15 +38,11 @@ $stmt->execute();
// Fetching. Prepare with client buffered cursor
$query = "SELECT TOP 1 cast(col1 as varchar) + '.00 EUR' FROM $tableName";
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL,
PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->execute();
$value = $stmt->fetchColumn();
var_dump ($value);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
//Free the statement and connection
$stmt = null;
$conn = null;

View file

@ -1,23 +1,22 @@
--TEST--
Bind integer parameters; allow fetch numeric types.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
/* Sample numbers MIN_INT, MAX_INT */
$sample = array(-2**31, 2**31-1);
/* Connect */
$conn_ops['pdo'][PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE] = TRUE;
$conn = new PDO("sqlsrv:server=$serverName", $username, $password, $conn_ops['pdo']);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd, $conn_ops['pdo']);
// Create table
$tableName = '#testPDO016';
$sql = "CREATE TABLE $tableName (c1 INT, c2 INT)";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (:num1, :num2)";
@ -32,9 +31,6 @@ $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_NUM);
var_dump ($row);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;

View file

@ -1,20 +1,18 @@
--TEST--
Fetch string with new line and tab characters
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Create table
$sql = "CREATE TABLE ".$tableName.
" (c1 VARCHAR(32), c2 CHAR(32), c3 NVARCHAR(32), c4 NCHAR(32))";
$stmt = $conn->query($sql);
$tableName = '#pdo_017';
$sql = "CREATE TABLE $tableName (c1 VARCHAR(32), c2 CHAR(32), c3 NVARCHAR(32), c4 NCHAR(32))";
$stmt = $conn->exec($sql);
// Bind parameters and insert data
$sql = "INSERT INTO $tableName VALUES (:val1, :val2, :val3, :val4)";
@ -28,14 +26,11 @@ $stmt->execute();
// Get data
$sql = "SELECT UPPER(c1) AS VARCHAR, UPPER(c2) AS CHAR,
UPPER(c3) AS NVARCHAR, UPPER(c4) AS NCHAR FROM $tableName";
UPPER(c3) AS NVARCHAR, UPPER(c4) AS NCHAR FROM $tableName";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt=null;
$conn=null;

View file

@ -1,19 +1,18 @@
--TEST--
Moves the cursor to the next result set
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
/* Connect */
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Create table
$tableName = '#testResultSet';
$sql = "CREATE TABLE $tableName (c1 INT, c2 VARCHAR(40))";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (?,?)";
@ -41,9 +40,6 @@ echo $a['c1'] . "|" . $a['c2'] . "\n";
foreach ($data2 as $a)
echo $a[0] . "|" . $a[1] . "\n";
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;

View file

@ -1,24 +1,23 @@
--TEST--
Moves the cursor to the next result set with pooling enabled
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Create a pool
$conn0 = new PDO("sqlsrv:server=$serverName;ConnectionPooling=1", $username, $password);
$conn0 = new PDO("sqlsrv:server=$server; database=$databaseName;ConnectionPooling=1", $uid, $pwd);
$conn0->query("SELECT 1");
$conn0 = null;
// Connect
$conn = new PDO("sqlsrv:server=$serverName;ConnectionPooling=1", $username, $password);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName;ConnectionPooling=1", $uid, $pwd);
// Create table
$tableName = '#nextResultPooling';
$sql = "CREATE TABLE $tableName (c1 INT, c2 XML)";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (?,?)";
@ -46,9 +45,6 @@ echo $a['c1']."|".$a['c2']."\n";
foreach ($data2 as $a)
echo $a[0] . "|".$a[1]."\n";
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;

View file

@ -1,19 +1,18 @@
--TEST--
Bind parameters using an array
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Create table
$tableName = '#bindParams';
$sql = "CREATE TABLE $tableName (ID TINYINT, SID CHAR(5))";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (?,?)";
@ -41,9 +40,6 @@ $data = $stmt->fetchAll();
foreach ($data as $a)
echo $a['ID'] . "|" . $a['SID'] . "\n";
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;

View file

@ -1,19 +1,18 @@
--TEST--
Bind parameters VARCHAR(n) extended ASCII
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Create table
$tableName = '#extendedAscii';
$sql = "CREATE TABLE $tableName (code CHAR(2), city VARCHAR(32))";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (?,?)";
@ -36,9 +35,6 @@ $data = $stmt->fetchAll();
foreach ($data as $a)
echo $a[0] . "|" . $a[1] . "\n";
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;

View file

@ -1,20 +1,19 @@
--TEST--
Unicode XML message using bindValue()
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO("sqlsrv:server=$serverName;", $username, $password);
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Create database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
// Create table
// Create a temporary table
$tableName = '#testXMLBindValue';
$sql = "CREATE TABLE $tableName (ID INT PRIMARY KEY NOT NULL IDENTITY, XMLMessage XML)";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// XML samples
$xml1 = '<?xml version="1.0" encoding="UTF-16"?>
@ -35,7 +34,7 @@ try
$stmt = $conn->prepare("INSERT INTO $tableName (XMLMessage) VALUES (:msg)");
$stmt->bindValue(':msg', $xml1);
$stmt->execute();
$stmt = $conn->prepare("INSERT INTO $tableName (XMLMessage) VALUES (?)");
$stmt->bindValue(1, $xml2);
$stmt->execute();
@ -48,10 +47,7 @@ catch (PDOException $ex) {
$stmt = $conn->query("select * from $tableName");
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($row);
// Drop database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt=null;
$conn=null;

View file

@ -3,16 +3,13 @@ Bind values with PDO::PARAM_BOOL, enable/disable fetch numeric type attribute
--SKIPIF--
--FILE--
<?php
require("autonomous_setup.php");
require("MsSetup.inc");
// Sample data
$sample = array([true, false],[-12, 0x2A],[0.00, NULL]);
// Connect
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// Create database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Run test
Test();
@ -25,9 +22,6 @@ Test();
$conn->setAttribute(PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, TRUE);
Test();
// Drop database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;
@ -37,33 +31,33 @@ print "Done";
// Generic test starts here
function Test()
{
global $conn, $tableName, $sample;
global $conn, $tableName, $sample;
// Drop table if exists
$sql = "IF OBJECT_ID('$tableName') IS NOT NULL DROP TABLE $tableName";
$stmt = $conn->query($sql);
// Create table
$sql = "CREATE TABLE $tableName (c1 INT, c2 BIT)";
$stmt = $conn->query($sql) ?: die();
// Drop table if exists
$sql = "IF OBJECT_ID('$tableName') IS NOT NULL DROP TABLE $tableName";
$stmt = $conn->query($sql);
// Create table
$sql = "CREATE TABLE $tableName (c1 INT, c2 BIT)";
$stmt = $conn->query($sql) ?: die();
// Insert data using bind values
$sql = "INSERT INTO $tableName VALUES (:v1, :v2)";
foreach ($sample as $s) {
$stmt = $conn->prepare($sql);
$stmt->bindValue(':v1', $s[0], PDO::PARAM_BOOL);
$stmt->bindValue(':v2', $s[1], PDO::PARAM_BOOL);
$stmt->execute();
}
// Insert data using bind values
$sql = "INSERT INTO $tableName VALUES (:v1, :v2)";
$stmt = $conn->prepare($sql);
foreach ($sample as $s) {
$stmt->bindValue(':v1', $s[0], PDO::PARAM_BOOL);
$stmt->bindValue(':v2', $s[1], PDO::PARAM_BOOL);
$stmt->execute();
}
// Get data
$sql = "SELECT * FROM $tableName";
$stmt = $conn->query($sql);
$row = $stmt->fetchAll(PDO::FETCH_NUM);
// Get data
$sql = "SELECT * FROM $tableName";
$stmt = $conn->query($sql);
$row = $stmt->fetchAll(PDO::FETCH_NUM);
// Print out
for($i=0; $i<$stmt->rowCount(); $i++)
{ var_dump($row[$i][0]); var_dump($row[$i][1]); }
// Print out
for($i=0; $i<$stmt->rowCount(); $i++)
{ var_dump($row[$i][0]); var_dump($row[$i][1]); }
}
?>

View file

@ -1,21 +1,20 @@
--TEST--
GitHub Issue #35 binary encoding error when binding by name
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
function test()
{
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$dbName = "tempdb";
$conn = new PDO( "sqlsrv:server=$serverName ; database=$dbName", $username, $password);
$conn = new PDO( "sqlsrv:server=$server ; database=$databaseName", $uid, $pwd);
// Create a temp table
$number = rand(0,1000);
$tableName = "testTableIssue35" . "_" . $number;
$tableName = "#testTableIssue35";
$sql = "CREATE TABLE $tableName (Value varbinary(max))";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
$sql = "INSERT INTO $tableName VALUES (?)";
@ -33,8 +32,6 @@ function test()
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
var_dump($val1 === $value);
$stmt = $conn->query("DROP TABLE $tableName");
// Close connection
$stmt = null;

View file

@ -1,19 +1,18 @@
--TEST--
Retrieve error information; supplied values does not match table definition
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
// Create table
$tableName = '#pdo_040test';
$sql = "CREATE TABLE $tableName (code INT)";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data using bind parameters
// Number of supplied values does not match table definition
@ -25,9 +24,6 @@ $params = array(2010,"London");
$stmt->execute($params);
print_r($stmt->errorInfo());
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
// Close connection
$stmt = null;
$conn = null;

View file

@ -1,57 +1,56 @@
--TEST--
Prepare, execute statement and fetch with pooling unset (default)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Allow PHP types for numeric fields
$connection_options['pdo'][PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE] = TRUE;
// Create a pool
$conn0 = new PDO( "sqlsrv:server=$serverName;",
$username, $password, $connection_options['pdo']);
$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;",
$uid, $pwd, $connection_options['pdo']);
$conn0 = null;
// Connection can use an existing pool
$conn = new PDO( "sqlsrv:server=$serverName;",
$username, $password, $connection_options['pdo']);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;",
$uid, $pwd, $connection_options['pdo']);
// Create table
$tableName = 'pdo_060_test';
$sql = "CREATE TABLE $tableName (Столица NVARCHAR(32), year INT)";
$stmt = $conn->query($sql);
// Insert data
$sql = "INSERT INTO ".$tableName." VALUES (?,?)";
$sql = "INSERT INTO $tableName VALUES (?,?)";
$stmt = $conn->prepare($sql);
$stmt->execute(array("Лондон",2012));
// Get data
$stmt = $conn->query("select * from $tableName");
$stmt = $conn->query("SELECT * FROM $tableName");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
$conn = null;
// Create a new pool
$conn0 = new PDO( "sqlsrv:server=$serverName;",
$username, $password);
$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;",
$uid, $pwd);
$conn0 = null;
// Connection can use an existing pool
$conn = new PDO( "sqlsrv:server=$serverName;",
$username, $password);
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;",
$uid, $pwd);
// Get data
$stmt = $conn->query("select * from $tableName");
$stmt = $conn->query("SELECT * FROM $tableName");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
$conn->query("DROP TABLE $tableName");
// Close connection
$stmt=null;
$conn=null;

View file

@ -1,57 +1,55 @@
--TEST--
Prepare, execute statement and fetch with pooling enabled
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Allow PHP types for numeric fields
$connection_options['pdo'][PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE] = TRUE;
// Create a pool
$conn0 = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=1;",
$username, $password, $connection_options['pdo']);
$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;",
$uid, $pwd, $connection_options['pdo']);
$conn0 = null;
// Connection can use an existing pool
$conn = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=1;",
$username, $password, $connection_options['pdo']);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;",
$uid, $pwd, $connection_options['pdo']);
// Create table
$tableName = 'pdo_061test';
$sql = "CREATE TABLE $tableName (Столица NVARCHAR(32), year INT)";
$stmt = $conn->query($sql);
// Insert data
$sql = "INSERT INTO ".$tableName." VALUES (?,?)";
$sql = "INSERT INTO $tableName VALUES (?,?)";
$stmt = $conn->prepare($sql);
$stmt->execute(array("Лондон",2012));
// Get data
$stmt = $conn->query("select * from $tableName");
$stmt = $conn->query("SELECT * FROM $tableName");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
$conn = null;
// Create a new pool
$conn0 = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=1;",
$username, $password);
$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;",
$uid, $pwd);
$conn0 = null;
// Connection can use an existing pool
$conn = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=1;",
$username, $password);
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=1;",
$uid, $pwd);
// Get data
$stmt = $conn->query("select * from $tableName");
$stmt = $conn->query("SELECT * FROM $tableName");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
$conn->query("DROP TABLE $tableName");
// Close connection
$stmt=null;
$conn=null;

View file

@ -1,56 +1,55 @@
--TEST--
Prepare, execute statement and fetch with pooling disabled
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Allow PHP types for numeric fields
$connection_options['pdo'][PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE] = TRUE;
// Create a pool
$conn0 = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=0;",
$username, $password, $connection_options['pdo']);
$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;",
$uid, $pwd, $connection_options['pdo']);
$conn0 = null;
// Connection can use an existing pool
$conn = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=0;",
$username, $password, $connection_options['pdo']);
// CREATE database
$conn->query("CREATE DATABASE ". $dbName) ?: die();
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;",
$uid, $pwd, $connection_options['pdo']);
// Create table
$tableName = 'pdo_62test';
$sql = "CREATE TABLE $tableName (Столица NVARCHAR(32), year INT)";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
// Insert data
$sql = "INSERT INTO ".$tableName." VALUES (?,?)";
$sql = "INSERT INTO $tableName VALUES (?,?)";
$stmt = $conn->prepare($sql);
$stmt->execute(array("Лондон",2012));
// Get data
$stmt = $conn->query("select * from $tableName");
$stmt = $conn->query("SELECT * FROM $tableName");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
$conn = null;
// Create a new pool
$conn0 = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=0;",
$username, $password);
$conn0 = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;",
$uid, $pwd);
$conn0 = null;
// Connection can use an existing pool
$conn = new PDO( "sqlsrv:server=$serverName;ConnectionPooling=0;",
$username, $password);
// Connection can use an existing pool?
$conn = new PDO( "sqlsrv:server=$server;database=$databaseName;ConnectionPooling=0;",
$uid, $pwd);
// Get data
$stmt = $conn->query("select * from $tableName");
$stmt = $conn->query("SELECT * FROM $tableName");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($row);
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
$conn->query("DROP TABLE $tableName");
// Close connection
$stmt=null;

View file

@ -1,36 +1,37 @@
--TEST--
Exception is thrown if the unsupported attribute ATTR_PERSISTENT is put into the connection options
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'pdo_tools.inc';
require_once("autonomous_setup.php");
$database = "tempdb";
$dsn = "sqlsrv:Server = $serverName;Database = $database;";
include 'MsSetup.inc';
$dsn = "sqlsrv:Server = $server;database = $databaseName;";
try{
echo "Testing a connection with ATTR_PERSISTENT...\n";
// setting PDO::ATTR_PERSISTENT in PDO constructor returns an exception
$attr = array(PDO::ATTR_PERSISTENT => true);
$conn = new PDO( $dsn, $username, $password, $attr);
$conn = new PDO( $dsn, $uid, $pwd, $attr);
//free the connection
$conn=null;
}
catch( PDOException $e ) {
echo "Exception from unsupported attribute (ATTR_PERSISTENT) is caught\n";
//exit;
}
try{
require_once 'MsCommon.inc';
echo "\nTesting new connection after exception thrown in previous connection...\n";
$tableName1 = GetTempTableName('tab1', false);
$conn = new PDO( $dsn, $username, $password );
$tableName1 = GetTempTableName('tab1');
$conn = new PDO( $dsn, $uid, $pwd );
$sql = "CREATE TABLE $tableName1 (c1 int, c2 varchar(10))";
$stmt = $conn->query($sql);
$stmt = $conn->exec($sql);
$ret = $conn->exec("INSERT INTO $tableName1 VALUES(1, 'column2')");
$stmt = $conn->query("SELECT * FROM $tableName1");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result['c1'] == 1 && $result['c2'] == 'column2') {
echo "Test successfully";
echo "Test successfully completed";
}
//free the statement and connection
$stmt = null;
@ -45,4 +46,4 @@ Testing a connection with ATTR_PERSISTENT...
Exception from unsupported attribute (ATTR_PERSISTENT) is caught
Testing new connection after exception thrown in previous connection...
Test successfully
Test successfully completed

View file

@ -1,22 +1,23 @@
--TEST--
Test unsupported connection attribute ATTR_PREFETCH
--DESCRIPTION--
Exception is thrown for the unsupported connection attribute ATTR_PREFETCH only if it is set after PDO::ERRMODE_EXCEPTION is turned on
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'pdo_tools.inc';
require_once("autonomous_setup.php");
$database = "tempdb";
$dsn = "sqlsrv:Server = $serverName;Database = $database;";
require_once("MsSetup.inc");
$dsn = "sqlsrv:Server = $server;database = $databaseName";
try{
echo "Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...\n";
$attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$conn = new PDO( $dsn, $username, $password, $attr);
$conn = new PDO( $dsn, $uid, $pwd, $attr);
echo "Error from supported attribute (ATTR_PREFETCH) is silented\n\n";
$conn=null;
echo "Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION...\n";
$attr = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PREFETCH => true);
$conn = new PDO( $dsn, $username, $password, $attr);
$conn = new PDO( $dsn, $uid, $pwd, $attr);
//free the connection
$conn=null;
}

View file

@ -1,12 +1,13 @@
--TEST--
GitHub issue #69 - fetching an empty nvarchar using client buffer
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
// Connect
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "EXEC dbo.sp_executesql

View file

@ -1,17 +1,16 @@
--TEST--
Test emulate prepare utf8 encoding set at the statement level
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$pdo_options = [];
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$pdo_options[PDO::SQLSRV_ATTR_ENCODING] = PDO::SQLSRV_ENCODING_UTF8;
$database = "tempdb";
$connection = new \PDO("sqlsrv:server=$serverName;Database=$database", $username, $password, $pdo_options);
$connection = new PDO("sqlsrv:server=$server;Database=$databaseName", $uid, $pwd, $pdo_options);
$pdo_options = array();
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE;

View file

@ -0,0 +1,186 @@
--TEST--
Github 138. Test for Unicode Column Metadata.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
class MyStatement extends PDOStatement {
public function BindValues(array &$values, array &$blobs, $placeholder_prefix, $columnInformation, &$max_placeholder = NULL, $blob_suffix = NULL) {
if (empty($max_placeholder)) {
$max_placeholder = 0;
}
foreach ($values as $field_name => &$field_value) {
$placeholder = $placeholder_prefix . $max_placeholder++;
$blob_key = $placeholder . $blob_suffix;
if (isset($columnInformation['blobs'][$field_name])) {
$blobs[$blob_key] = fopen('php://memory', 'a');
fwrite($blobs[$blob_key], $field_value);
rewind($blobs[$blob_key]);
$this->bindParam($placeholder, $blobs[$blob_key], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
}
else {
// Even though not a blob, make sure we retain a copy of these values.
$blobs[$blob_key] = $field_value;
$this->bindParam($placeholder, $blobs[$blob_key], PDO::PARAM_STR);
}
}
}
}
/**
*
* @param string $connection_id
*
* @return PDO
*/
function connection($connection_id) {
include 'MsSetup.inc';
$host = $server;
$database = $databaseName;
$username = $uid;
$password = $pwd;
static $connections = array();
if (!isset($connections[$connection_id])) {
$connection_options['pdo'] = array();
$connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$cnn = new PDO("sqlsrv:server=$host;Database=$database", $username, $password, $connection_options['pdo']);
$cnn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [MyStatement::class]);
$connections[$connection_id] = $cnn;
}
return $connections[$connection_id];
}
/**
* Summary of prepare
*
* @param mixed $connection
* @param mixed $query
* @return PDOStatement
*/
function prepare($connection, $query) {
$pdo_options = array();
$pdo_options[PDO::ATTR_EMULATE_PREPARES] = TRUE;
$pdo_options[PDO::SQLSRV_ATTR_DIRECT_QUERY] = TRUE;
$pdo_options[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL;
$pdo_options[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED;
return $connection->prepare($query, $pdo_options);
}
/**
* Summary of execute
*
* @param PDO $connection
* @param string $query
*
* @param PDOStatement;
*/
function execute($connection, $query, array $args = array()) {
$st = prepare($connection, $query);
foreach ($args as $key => $value) {
if (is_numeric($value)) {
$st->bindValue($key, $value, PDO::PARAM_INT);
}
else {
$st->bindValue($key, $value, PDO::PARAM_STR);
}
}
$st->execute();
// Bind column types properly.
$null = array();
$st->columnNames = array();
for ($i = 0; $i < $st->columnCount(); $i++) {
$meta = $st->getColumnMeta($i);
$st->columnNames[]= $meta['name'];
$sqlsrv_type = $meta['sqlsrv:decl_type'];
$parts = explode(' ', $sqlsrv_type);
$type = reset($parts);
switch($type) {
case 'varbinary':
$null[$i] = NULL;
$st->bindColumn($i + 1, $null[$i], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
break;
case 'int':
case 'bit':
case 'smallint':
case 'tinyint':
case 'bigint':
$null[$i] = NULL;
$st->bindColumn($i + 1, $null[$i], PDO::PARAM_INT);
break;
}
}
return $st;
}
//*******************************************************
// TEST BEGIN
//*******************************************************
$connection = connection('default');
// Drop
try {
execute($connection, 'DROP TABLE [mytáble]');
}
catch(Exception $e) {}
$tablescript = <<<EOF
CREATE TABLE [dbo].[mytáble](
[id] [nchar](10) NULL,
[väriable] [nchar](10) NULL,
[tésting] [nchar](10) NULL
) ON [PRIMARY]
EOF;
// Recreate
execute($connection, $tablescript);
$query = <<<EOF
INSERT INTO [mytáble] (id, tésting, väriable) VALUES (:db_insert0, :db_insert1, :db_insert2)
EOF;
$blobs = [];
/** @var MyStatement */
$st = prepare($connection, $query);
$st->bindValue(':db_insert0', 'a', PDO::PARAM_STR);
$st->bindValue(':db_insert1', 'b', PDO::PARAM_STR);
$st->bindValue(':db_insert2', 'c', PDO::PARAM_STR);
$st->execute();
$st = prepare($connection, 'SELECT * FROM [mytáble]');
$st->execute();
while($row = $st->fetchAll()){
$row = reset($row);
echo (isset($row['id']) ? "OK" : "FAIL") , "\n";
echo (isset($row['tésting']) ? "OK" : "FAIL") , "\n";
echo (isset($row['väriable']) ? "OK" : "FAIL") , "\n";
}
for ($i = 0; $i < $st->columnCount(); $i++) {
$meta = $st->getColumnMeta($i);
echo $meta['name'] , "\n";
}
?>
--EXPECT--
OK
OK
OK
id
väriable
tésting

View file

@ -1,11 +1,12 @@
--TEST--
Test emulate prepare with mix bound param encodings including binary data
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
class MyStatement extends \PDOStatement {
class MyStatement extends PDOStatement {
public function BindValues(array &$values, array &$blobs, $placeholder_prefix, $columnInformation, &$max_placeholder = NULL, $blob_suffix = NULL) {
if (empty($max_placeholder)) {
$max_placeholder = 0;
@ -36,7 +37,7 @@ $connection_options['pdo'] = array();
$connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$database = "tempdb";
$cnn = new PDO("sqlsrv:Server=$serverName;Database=$database", $username, $password, $connection_options['pdo']);
$cnn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd, $connection_options['pdo']);
$cnn->setAttribute(PDO::ATTR_STATEMENT_CLASS, [MyStatement::class]);
// Drop

View file

@ -1,15 +1,15 @@
--TEST--
Test emulate prepare with mix bound param encodings and positional placeholders (i.e., using '?' as placeholders)
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$connection_options['pdo'] = array();
$connection_options['pdo'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$database = "tempdb";
$cnn = new PDO("sqlsrv:Server=$serverName;Database=$database", $username, $password, $connection_options['pdo']);
$cnn = new PDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd, $connection_options['pdo']);
// Drop
try {

View file

@ -1,50 +1,50 @@
--TEST--
sqlsrv_has_rows() using a forward and scrollable cursor
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
// Connect
$conn = new PDO( "sqlsrv:server=$serverName" , $username, $password);
$conn = new PDO( "sqlsrv:server=$server; database=$databaseName" , $uid, $pwd);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// Create database
$conn->query("CREATE DATABASE ". $dbName);
// Create table
$stmt = $conn->query("CREATE TABLE ".$dbName.".[dbo].[php_test_table_1] ([c1_int] int, [c2_varchar] varchar(1000))");
$query = "INSERT INTO ".$dbName.".[dbo].[php_test_table_1] (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb</üöîã,ZbOhߢAåb*öî:r>:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<<AA*¢ã@Uî:B<öBîÐ>z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>å<býUrAA©r£@üÄb_:ãZß_/ou@|ªåü~ACãUO<£îßÄîäbßöhßO©ZvßOBü:Zä<ĪobbO@ÃÐ_~î|a~ð©+,v+Ð/rÃzuöÖZÐOß/CCÖßý¢:<b£B,ÐߢoZbð~BüOö,Üö~ð:ß,CCî<Oä,Öãî£ÜCZ~/z~ý©vuzoöß/u©å|£ãÐv¢îhý:ÄoÐrz.ßbr_U*<hCîßÖ_+:hbü*að.Aö_Oª_öB>Bã_ý*ah¢rOĪ,ßo¢¢a|BÖäz</bUabÖðOA.Ðîý,Bhö*Cßuߣo,|ü_,ýÐu_b|ZÜh|<U@~übU¢Uð/o/Ð>U£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))";
// Create temporary table2
$tableName1 = '#pdo_228_1';
$tableName2 = '#pdo_228_2';
$stmt = $conn->exec("CREATE TABLE $tableName1 ([c1_int] int, [c2_varchar] varchar(1000))");
$query = "INSERT INTO $tableName1 (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb</üöîã,ZbOhߢAåb*öî:r>:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<<AA*¢ã@Uî:B<öBîÐ>z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>å<býUrAA©r£@üÄb_:ãZß_/ou@|ªåü~ACãUO<£îßÄîäbßöhßO©ZvßOBü:Zä<ĪobbO@ÃÐ_~î|a~ð©+,v+Ð/rÃzuöÖZÐOß/CCÖßý¢:<b£B,ÐߢoZbð~BüOö,Üö~ð:ß,CCî<Oä,Öãî£ÜCZ~/z~ý©vuzoöß/u©å|£ãÐv¢îhý:ÄoÐrz.ßbr_U*<hCîßÖ_+:hbü*að.Aö_Oª_öB>Bã_ý*ah¢rOĪ,ßo¢¢a|BÖäz</bUabÖðOA.Ðîý,Bhö*Cßuߣo,|ü_,ýÐu_b|ZÜh|<U@~übU¢Uð/o/Ð>U£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))";
$stmt = $conn->query($query);
$stmt = $conn->query("CREATE TABLE ".$dbName.".[dbo].[php_test_table_2] ([c1_int] int, [c2_varchar] varchar(max))");
$query = "INSERT INTO ".$dbName.".[dbo].[php_test_table_2] (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb</üöîã,ZbOhߢAåb*öî:r>:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<<AA*¢ã@Uî:B<öBîÐ>z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>å<býUrAA©r£@üÄb_:ãZß_/ou@|ªåü~ACãUO<£îßÄîäbßöhßO©ZvßOBü:Zä<ĪobbO@ÃÐ_~î|a~ð©+,v+Ð/rÃzuöÖZÐOß/CCÖßý¢:<b£B,ÐߢoZbð~BüOö,Üö~ð:ß,CCî<Oä,Öãî£ÜCZ~/z~ý©vuzoöß/u©å|£ãÐv¢îhý:ÄoÐrz.ßbr_U*<hCîßÖ_+:hbü*að.Aö_Oª_öB>Bã_ý*ah¢rOĪ,ßo¢¢a|BÖäz</bUabÖðOA.Ðîý,Bhö*Cßuߣo,|ü_,ýÐu_b|ZÜh|<U@~übU¢Uð/o/Ð>U£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))";
$stmt = $conn->exec("CREATE TABLE $tableName2 ([c1_int] int, [c2_varchar] varchar(max))");
$query = "INSERT INTO $tableName2 (c1_int, c2_varchar) VALUES ((990021574), ('>vh~Ö.bÐ*äß/ÄAabýZâOüzr£ðAß+|~|OU¢a|U<ßrv.uCB.ÐÜh_î+ãå@üðöã,U+ßvuU:/ý_Öãî/ð|bB|_Zbua©r++BA¢z£.üî¢öåäözÜ¢ßb</üöîã,ZbOhߢAåb*öî:r>:aöCrÄ~ýZ¢uªÐö.hhßð*zÜÜß*ãüåýãÄ+åýüüaߢÃÐBî@~AZöÃOßC@äoÃuCÜ,ÐÄa:îäÄÖý:h*ouªuåvUz_ArßAªãaãvÐåAUüAB:¢Äz|öub<üZvößüå:ãÄ@r/ZAÄðÄÄvzîv~C/£|ýýbüÖ~£|Öå<Üa~/v@åAz©¢£U_ßhbaÃß,zz<ã¢|<ä©>öAuövÖ>abu,zå,+ß/ü/ª_bbB:ÃC~£ü/O©O©ªAª_,|a¢~ýý/b>ßC@/böîöh>~£ð+Bßr©ÄÐÖßã:bA@:>B:UAbããîÜ~uÜ£îCöÖ£©_ÜßzÐ+ÖýZb,A:<<AA*¢ã@Uî:B<öBîÐ>z.ãîÄzC@©*ä|ã._ßZOäb¢Cßovå+uv.£B~~b£ª|ÖÄîßö>©Ãbb|©©ðA£åO~âãüîuvÄÜýUzîOÖ/oOßO*>ªßzêÖÐböÄåbîðîÐa~©ßîÄßУ<î>å<býUrAA©r£@üÄb_:ãZß_/ou@|ªåü~ACãUO<£îßÄîäbßöhßO©ZvßOBü:Zä<ĪobbO@ÃÐ_~î|a~ð©+,v+Ð/rÃzuöÖZÐOß/CCÖßý¢:<b£B,ÐߢoZbð~BüOö,Üö~ð:ß,CCî<Oä,Öãî£ÜCZ~/z~ý©vuzoöß/u©å|£ãÐv¢îhý:ÄoÐrz.ßbr_U*<hCîßÖ_+:hbü*að.Aö_Oª_öB>Bã_ý*ah¢rOĪ,ßo¢¢a|BÖäz</bUabÖðOA.Ðîý,Bhö*Cßuߣo,|ü_,ýÐu_b|ZÜh|<U@~übU¢Uð/o/Ð>U£.B£@Ü,ßAÃ>,ðßß+ßÜ©|Ðr©bCðТüãz>AßðåÃ>bÄåÄ|Z~äÃ/Cb*£bð_/Ða@~AÜãO+ý*CîîÃzÄöÃa©+@vuz>î>©.Cv>hÃý>©Bä,ö~@~@r,AðCu@Ü,@U*ÐvöÃêuã.Öa*uZªoZ/ðÖ©ßv_<ÖvåÜÐÜOÐoðßðÃUýZÐB:+ÄÃã£'))";
$stmt = $conn->query($query);
$size = 2;
$stmt = $conn->prepare("SELECT * FROM ".$dbName.".[dbo].[php_test_table_1]", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size));
$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE'));
$stmt = $conn->prepare("SELECT * FROM $tableName1", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size));
$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE'));
echo("Client Buffer Size in KB: $attr\n");
$stmt->execute();
$stmt->execute();
$numRows = 0;
while ($result = $stmt->fetch())
$numRows++;
$numRows++;
echo ("Number of rows: $numRows\n");
$size = 3;
$stmt = $conn->prepare("SELECT * FROM ".$dbName.".[dbo].[php_test_table_2]", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size));
$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE'));
$stmt = $conn->prepare("SELECT * FROM $tableName2", array(constant('PDO::ATTR_CURSOR') => PDO::CURSOR_SCROLL,PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED,PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE=> $size));
$attr = $stmt->getAttribute(constant('PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE'));
echo("Client Buffer Size in KB: $attr\n");
$stmt->execute();
$stmt->execute();
$numRows = 0;
while ($result = $stmt->fetch())
$numRows++;
$numRows++;
echo ("Number of rows: $numRows\n");
// DROP database
$conn->query("DROP DATABASE ". $dbName) ?: die();
$stmt=null;
$conn=null;
print "Done"

View file

@ -1,14 +1,15 @@
--TEST--
Test closeCursor with a stmt before/after execute and fetch.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
try
{
/* Connect */
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
// Connect
$conn = new PDO("sqlsrv:server=$server; database=$databaseName", $uid, $pwd);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// prepare a stmt but don't execute, then closeCursor.
@ -51,8 +52,8 @@ try
}
catch( PDOException $e ) {
var_dump($e);
exit;
var_dump($e);
exit;
}
print "Done";

View file

@ -3,17 +3,18 @@ Test fetch from binary, varbinary, varbinary(max), image columns, without settin
--DESCRIPTION--
Verifies GitHub issue 270 is fixed, users could not retrieve the data as inserted in binary columns without setting the binary encoding either on stmt or using bindCoulmn encoding.
This test verifies that the data inserted in binary columns can be retrieved using fetch, fetchColumn, fetchObject, and fetchAll functions.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsSetup.inc");
$tableName = 'test_binary'.rand();
$columns = array( 'col1', 'col2', 'col3', 'col4');
// Connect
$conn = new PDO( "sqlsrv:server=$serverName;Database=tempdb", $username, $password );
$conn = new PDO( "sqlsrv:server=$server; database=$databaseName", $uid, $pwd );
$sql = "CREATE TABLE $tableName ( $columns[0] binary(50), $columns[1] VARBINARY(50), $columns[2] VARBINARY(MAX), $columns[3] image)";
$conn->exec($sql);
@ -31,7 +32,7 @@ $stmt->execute();
// loop through each column in the table
foreach ($columns as $col){
test_fetch($conn, $tableName, $col, $icon);
test_fetch($conn, $tableName, $col, $icon);
}
// DROP table
$conn->query("DROP TABLE $tableName") ?: die();
@ -44,47 +45,47 @@ print_r("Test finished successfully");
//calls various fetch methods
function test_fetch($conn, $tableName, $columnName, $input){
$len = strlen($input);
$result = "";
$sql = "SELECT $columnName from $tableName";
$stmt = $conn->query($sql);
$stmt->bindColumn(1, $result, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
//binary is fixed size, to evaluate output, compare it using strncmp
if( strncmp($result, $input, $len) !== 0){
print_r("\nRetrieving using bindColumn failed");
}
$len = strlen($input);
$result = "";
$sql = "SELECT $columnName from $tableName";
$stmt = $conn->query($sql);
$stmt->bindColumn(1, $result, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
//binary is fixed size, to evaluate output, compare it using strncmp
if( strncmp($result, $input, $len) !== 0){
print_r("\nRetrieving using bindColumn failed");
}
$result = "";
$stmt = $conn->query($sql);
$stmt->bindColumn(1, $result, PDO::PARAM_LOB, 0 , PDO::SQLSRV_ENCODING_BINARY);
$stmt->fetch(PDO::FETCH_BOUND);
if( strncmp($result, $input, $len) !== 0){
print_r("\nRetrieving using bindColumn with encoding set failed");
}
$result = "";
$stmt = $conn->query($sql);
$stmt->bindColumn(1, $result, PDO::PARAM_LOB, 0 , PDO::SQLSRV_ENCODING_BINARY);
$stmt->fetch(PDO::FETCH_BOUND);
if( strncmp($result, $input, $len) !== 0){
print_r("\nRetrieving using bindColumn with encoding set failed");
}
$result = "";
$stmt = $conn->query($sql);
$result = $stmt->fetchColumn();
if( strncmp($result, $input, $len) !== 0){
print_r("\nRetrieving using fetchColumn failed");
}
$result = "";
$stmt = $conn->query($sql);
$result = $stmt->fetchColumn();
if( strncmp($result, $input, $len) !== 0){
print_r("\nRetrieving using fetchColumn failed");
}
$result = "";
$stmt = $conn->query($sql);
$result = $stmt->fetchObject();
if( strncmp($result->$columnName, $input, $len) !== 0){
print_r("\nRetrieving using fetchObject failed");
}
$result = "";
$stmt = $conn->query($sql);
$result = $stmt->fetchObject();
if( strncmp($result->$columnName, $input, $len) !== 0){
print_r("\nRetrieving using fetchObject failed");
}
$result = "";
$stmt = $conn->query($sql);
$result = $stmt->fetchAll( PDO::FETCH_COLUMN );
if( strncmp($result[0], $input, $len) !== 0){
print_r("\nRetrieving using fetchAll failed");
}
$result = "";
$stmt = $conn->query($sql);
$result = $stmt->fetchAll( PDO::FETCH_COLUMN );
if( strncmp($result[0], $input, $len) !== 0){
print_r("\nRetrieving using fetchAll failed");
}
}
?>

View file

@ -3,16 +3,14 @@ GitHub issue #308 - empty string set to output parameter on stored procedure
--DESCRIPTION--
Verifies GitHub issue 308 is fixed, empty string returned as output parameter will remain an empty string.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once("pdo_tools.inc");
require_once("MsCommon.inc");
// Connect
require_once("autonomous_setup.php");
$dbName = "tempdb";
$conn = new PDO("sqlsrv:server=$serverName;Database=$dbName", $username, $password);
require_once("MsSetup.inc");
$conn = new PDO("sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$procName = GetTempProcName();

View file

@ -3,13 +3,13 @@ GitHub issue #336 - PDO::exec should not return an error with query returning SQ
--DESCRIPTION--
Verifies GitHub issue 336 is fixed, PDO::exec on query returning SQL_NO_DATA will not give an error
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
// Connect
require_once("autonomous_setup.php");
$dbName = "tempdb";
require_once("MsSetup.inc");
$conn = new PDO("sqlsrv:server=$serverName;Database=$dbName", $username, $password);
$conn = new PDO("sqlsrv:server=$server;database=$databaseName", $uid, $pwd);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "DELETE FROM foo_table WHERE id = 42";

Some files were not shown because too many files have changed in this diff Show more