-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement throwing exception when ATTR_PERSISTENT is in the connectio…
…n options; added tests
- Loading branch information
1 parent
9bd42e4
commit b701fab
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
Exception is thrown if the unsupported attribute ATTR_PERSISTENT is put into the connection options | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
include 'pdo_tools.inc'; | ||
require_once("autonomous_setup.php"); | ||
$database = "tempdb"; | ||
$dsn = "sqlsrv:Server = $serverName;Database = $database;"; | ||
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); | ||
|
||
//free the statement and connection | ||
$stmt=null; | ||
$conn=null; | ||
} | ||
catch( PDOException $e ) { | ||
echo "Exception from unsupported attribute (ATTR_PERSISTENT) is caught\n"; | ||
//exit; | ||
} | ||
try{ | ||
echo "\nTesting new connection after exception thrown in previous connection...\n"; | ||
$tableName1 = GetTempTableName('tab1'); | ||
$conn = new PDO( $dsn, $username, $password ); | ||
$sql = "CREATE TABLE $tableName1 (c1 int, c2 varchar(10))"; | ||
$stmt = $conn->query($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"; | ||
} | ||
} | ||
catch( PDOException $e ) { | ||
var_dump( $e); | ||
} | ||
?> | ||
--EXPECT-- | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--TEST-- | ||
Exception is thrown for the unsupported connection attribute ATTR_PREFETCH only if it is set after PDO::ERRMODE_EXCEPTION is turned on | ||
--SKIPIF-- | ||
--FILE-- | ||
<?php | ||
include 'pdo_tools.inc'; | ||
require_once("autonomous_setup.php"); | ||
$database = "tempdb"; | ||
$dsn = "sqlsrv:Server = $serverName;Database = $database;"; | ||
try{ | ||
echo "Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION...\n"; | ||
// setting PDO::ATTR_PERSISTENT in PDO constructor returns an exception | ||
$attr = array(PDO::ATTR_PREFETCH => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); | ||
$conn = new PDO( $dsn, $username, $password, $attr); | ||
echo "Error from supported attribute (ATTR_PREFETCH) is silented\n\n"; | ||
|
||
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); | ||
//free the statement and connection | ||
$stmt=null; | ||
$conn=null; | ||
} | ||
catch( PDOException $e ) { | ||
echo "Exception from unsupported attribute (ATTR_PREFETCH) is caught\n"; | ||
//exit; | ||
} | ||
?> | ||
--EXPECT-- | ||
Testing a connection with ATTR_PREFETCH before ERRMODE_EXCEPTION... | ||
Error from supported attribute (ATTR_PREFETCH) is silented | ||
|
||
Testing a connection with ATTR_PREFETCH after ERRMODE_EXCEPTION... | ||
Exception from unsupported attribute (ATTR_PREFETCH) is caught |