pdo tests set 2
This commit is contained in:
parent
82527c743c
commit
bb364f989d
48
test/pdo_sqlsrv/pdo_bindparam_inout_binary_encoding.phpt
Normal file
48
test/pdo_sqlsrv/pdo_bindparam_inout_binary_encoding.phpt
Normal file
|
@ -0,0 +1,48 @@
|
|||
--TEST--
|
||||
bind inout param with PDO::SQLSRV_ENCODING_BINARY
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
$pdo = new PDO("sqlsrv:Server=$server ; Database = $databaseName ", $uid, $pwd);
|
||||
|
||||
$sql = "DROP TABLE my_table";
|
||||
$stmt = $pdo->query($sql);
|
||||
$stmt = null;
|
||||
|
||||
$sql = "CREATE TABLE my_table (value varchar(20), name varchar(20))";
|
||||
$stmt = $pdo->query($sql);
|
||||
$stmt = null;
|
||||
|
||||
$sql = "INSERT INTO my_table (value, name) VALUES ('Initial string', 'name')";
|
||||
$stmt = $pdo->query($sql);
|
||||
$stmt = null;
|
||||
|
||||
$value = 'Some string value.';
|
||||
$name = 'name';
|
||||
|
||||
$sql = "UPDATE my_table SET value = :value WHERE name = :name";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
$stmt->bindParam(':value', $value, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
|
||||
$stmt->bindParam(':name', $name);
|
||||
|
||||
$stmt->execute();
|
||||
$stmt = null;
|
||||
|
||||
$sql = "SELECT * FROM my_table";
|
||||
$stmt = $pdo->query($sql);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
print_r($result);
|
||||
|
||||
$stmt->closeCursor();
|
||||
$pdo = null;
|
||||
?>
|
||||
--EXPECT--
|
||||
Array
|
||||
(
|
||||
[value] => Some string value.
|
||||
[name] => name
|
||||
)
|
33
test/pdo_sqlsrv/pdo_error.phpt
Normal file
33
test/pdo_sqlsrv/pdo_error.phpt
Normal file
|
@ -0,0 +1,33 @@
|
|||
--TEST--
|
||||
Test the PDO::errorCode() and PDO::errorInfo() methods.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
$db = connect();
|
||||
// query with a wrong column name.
|
||||
$db->query( "Select * from " . $table1 . " where IntColX = 1" );
|
||||
}
|
||||
|
||||
catch( PDOException $e ) {
|
||||
print($db->errorCode());
|
||||
echo "\n";
|
||||
print_r($db->errorInfo());
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
42S22
|
||||
Array
|
||||
\(
|
||||
\[0\] => 42S22
|
||||
\[1\] => 207
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver (09|10|11|12|13) for SQL Server\]\[SQL Server\]Invalid column name 'IntColX'\.
|
||||
\)
|
43
test/pdo_sqlsrv/pdo_errorMode.phpt
Normal file
43
test/pdo_sqlsrv/pdo_errorMode.phpt
Normal file
|
@ -0,0 +1,43 @@
|
|||
--TEST--
|
||||
Test different error modes. The queries will try to do a select on a table that does not exist on database.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
|
||||
function testException(){
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
try{
|
||||
$q = $db->query($sql);
|
||||
} catch ( Exception $e ){
|
||||
echo 'Caught exception: ', $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function testWarning(){
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$q = $db->query($sql);
|
||||
}
|
||||
|
||||
function testSilent(){
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$q = $db->query($sql);
|
||||
}
|
||||
|
||||
|
||||
testException();
|
||||
testWarning();
|
||||
testSilent();
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Caught exception: SQLSTATE\[42S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Invalid object name 'temp_table'\.
|
||||
Warning: PDO::query\(\): SQLSTATE\[42S02\]: Base table or view not found: 208 \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Invalid object name 'temp_table'\. in .*pdo_errorMode\.php on line [0-9]+
|
108
test/pdo_sqlsrv/pdo_errorinfo_emulateprepare.phpt
Normal file
108
test/pdo_sqlsrv/pdo_errorinfo_emulateprepare.phpt
Normal file
|
@ -0,0 +1,108 @@
|
|||
--TEST--
|
||||
Test errorInfo when prepare with and without emulate prepare
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsSetup.inc';
|
||||
|
||||
$conn = new PDO("sqlsrv:server=$server;Database=$databaseName", $uid, $pwd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
|
||||
|
||||
//drop, create and insert
|
||||
$conn->query("IF OBJECT_ID('dbo.test_table', 'U') IS NOT NULL DROP TABLE dbo.test_table");
|
||||
$conn->query("CREATE TABLE [dbo].[test_table](c1 int, c2 int)");
|
||||
$conn->query("INSERT INTO [dbo].[test_table] VALUES (1, 10)");
|
||||
$conn->query("INSERT INTO [dbo].[test_table] VALUES (2, 20)");
|
||||
|
||||
echo "\n****testing with emulate prepare****\n";
|
||||
$stmt = $conn->prepare("SELECT c2 FROM test_table WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => true));
|
||||
|
||||
$int_col = 1;
|
||||
//bind param with the wrong parameter name to test for errorInfo
|
||||
$stmt->bindParam(':in', $int_col);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
echo "Statement error info:\n";
|
||||
print_r($stmt->errorInfo());
|
||||
|
||||
if ($stmt->errorInfo()[1] == NULL && $stmt->errorInfo()[2] == NULL) {
|
||||
echo "stmt native code and native message are NULL.\n";
|
||||
}
|
||||
else {
|
||||
echo "stmt native code and native message should be NULL.\n";
|
||||
}
|
||||
|
||||
echo "Connection error info:\n";
|
||||
print_r($conn->errorInfo());
|
||||
|
||||
if ($conn->errorInfo()[1] == NULL && $conn->errorInfo()[2] == NULL) {
|
||||
echo "conn native code and native message are NULL.\n";
|
||||
}
|
||||
else {
|
||||
echo "conn native code and native message shoud be NULL.\n";
|
||||
}
|
||||
|
||||
echo "\n****testing without emulate prepare****\n";
|
||||
$stmt2 = $conn->prepare("SELECT c2 FROM test_table WHERE c1= :int", array(PDO::ATTR_EMULATE_PREPARES => false));
|
||||
|
||||
$int_col = 2;
|
||||
//bind param with the wrong parameter name to test for errorInfo
|
||||
$stmt2->bindParam(':it', $int_col);
|
||||
|
||||
$stmt2->execute();
|
||||
|
||||
echo "Statement error info:\n";
|
||||
print_r($stmt2->errorInfo());
|
||||
|
||||
echo "Connection error info:\n";
|
||||
print_r($conn->errorInfo());
|
||||
|
||||
$conn->query("IF OBJECT_ID('dbo.test_table', 'U') IS NOT NULL DROP TABLE dbo.test_table");
|
||||
$stmt = NULL;
|
||||
$stmt2 = NULL;
|
||||
$conn = NULL;
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
\*\*\*\*testing with emulate prepare\*\*\*\*
|
||||
|
||||
Warning: PDOStatement::execute\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+
|
||||
|
||||
Warning: PDOStatement::execute\(\): SQLSTATE\[HY093\]: Invalid parameter number in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+
|
||||
Statement error info:
|
||||
Array
|
||||
\(
|
||||
\[0\] => HY093
|
||||
\[1\] =>
|
||||
\[2\] =>
|
||||
\)
|
||||
stmt native code and native message are NULL\.
|
||||
Connection error info:
|
||||
Array
|
||||
\(
|
||||
\[0\] => 00000
|
||||
\[1\] =>
|
||||
\[2\] =>
|
||||
\)
|
||||
conn native code and native message are NULL\.
|
||||
|
||||
\*\*\*\*testing without emulate prepare\*\*\*\*
|
||||
|
||||
Warning: PDOStatement::bindParam\(\): SQLSTATE\[HY093\]: Invalid parameter number: parameter was not defined in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+
|
||||
|
||||
Warning: PDOStatement::execute\(\): SQLSTATE\[07002\]: COUNT field incorrect: 0 \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]COUNT field incorrect or syntax error in .+(\/|\\)pdo_errorinfo_emulateprepare\.php on line [0-9]+
|
||||
Statement error info:
|
||||
Array
|
||||
\(
|
||||
\[0\] => 07002
|
||||
\[1\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]COUNT field incorrect or syntax error
|
||||
\)
|
||||
Connection error info:
|
||||
Array
|
||||
\(
|
||||
\[0\] => 00000
|
||||
\[1\] =>
|
||||
\[2\] =>
|
||||
\)
|
50
test/pdo_sqlsrv/pdo_exec.phpt
Normal file
50
test/pdo_sqlsrv/pdo_exec.phpt
Normal file
|
@ -0,0 +1,50 @@
|
|||
--TEST--
|
||||
Test the PDO::exec() method.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
$db = connect();
|
||||
|
||||
$sql = "CREATE TABLE #tmp_table(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))";
|
||||
$numRows = $db->exec($sql);
|
||||
if($numRows === false)
|
||||
{
|
||||
die("Create table failed\n");
|
||||
}
|
||||
var_dump($numRows);
|
||||
|
||||
$sql = "INSERT INTO #tmp_table VALUES(1, 'A')";
|
||||
$numRows = $db->exec($sql);
|
||||
var_dump($numRows);
|
||||
|
||||
$sql = "INSERT INTO #tmp_table VALUES(2, 'B')";
|
||||
$numRows = $db->exec($sql);
|
||||
var_dump($numRows);
|
||||
|
||||
$numRows = $db->exec("UPDATE #tmp_table SET val = 'X' WHERE id > 0");
|
||||
var_dump($numRows);
|
||||
|
||||
$numRows = $db->exec("DELETE FROM #tmp_table");
|
||||
var_dump($numRows);
|
||||
|
||||
}
|
||||
|
||||
catch( PDOException $e ) {
|
||||
var_dump( $e );
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
int(0)
|
||||
int(1)
|
||||
int(1)
|
||||
int(2)
|
||||
int(2)
|
25
test/pdo_sqlsrv/pdo_getAvailableDrivers.phpt
Normal file
25
test/pdo_sqlsrv/pdo_getAvailableDrivers.phpt
Normal file
|
@ -0,0 +1,25 @@
|
|||
--TEST--
|
||||
Test the PDO::getAvailableDrivers() method.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
// Do not print anything, as the result will be different for each computer
|
||||
$result = PDO::getAvailableDrivers();
|
||||
echo "Test successful.";
|
||||
}
|
||||
|
||||
catch( PDOException $e ) {
|
||||
var_dump( $e );
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test successful.
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding binary parameters
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding varchar
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding integer
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding integer
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding integer
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding integer
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding integer
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
prepare with emulate prepare and binding uft8 characters
|
||||
--SKIPIF--
|
||||
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require('MsSetup.inc');
|
||||
|
|
Loading…
Reference in a new issue