Skip to content

Commit 4f01ca3

Browse files
committed
Test fix for procedural ODBC pconn close
While this issue affects any driver, getting a driver into a state that persists across persistent connections is driver specific, be it wedged or just some connection variables. As such, just make an SQL Server specific test, since that's the driver used in CI.
1 parent 7927647 commit 4f01ca3

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
odbc_pconnect(): Make sure closing a persistent connection works
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php
7+
8+
include 'skipif.inc';
9+
10+
// The test can affect multiple drivers, but testing it is driver-specific.
11+
// Since CI runs ODBC tests with SQL Server, just use an SQL Server specific way of testing.
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
$result = @odbc_exec($conn, "SELECT @@Version");
14+
if ($result) {
15+
$array = odbc_fetch_array($result);
16+
$info = (string) reset($array);
17+
if (!str_contains($info, "Microsoft SQL Server")) {
18+
echo "skip MS SQL specific test";
19+
}
20+
}
21+
?>
22+
--FILE--
23+
<?php
24+
25+
include 'config.inc';
26+
27+
// set a session specific variable via CONTEXT_INFO, if we get the same connection again, it should be identical
28+
function set_context_info($conn, $string) {
29+
$hexstring = bin2hex($string);
30+
return odbc_exec($conn, "SET CONTEXT_INFO 0x$hexstring"); /* '*' */
31+
}
32+
33+
function fetch_context_info($conn) {
34+
$stmt = odbc_exec($conn, "SELECT CONTEXT_INFO() AS CONTEXT_INFO");
35+
if (!$stmt) {
36+
return false;
37+
}
38+
$res = odbc_fetch_array($stmt);
39+
if ($res) {
40+
// this is a binary, so we get a bunch of nulls at the end
41+
return $res["CONTEXT_INFO"] ? trim($res["CONTEXT_INFO"]) : null;
42+
} else {
43+
return false;
44+
}
45+
}
46+
47+
// run 1: set expectations
48+
$conn = odbc_pconnect($dsn, $user, $pass);
49+
set_context_info($conn, "PHP odbc_pconnect test");
50+
var_dump(fetch_context_info($conn));
51+
52+
// run 2: reuse same connection (imagine this is another request)
53+
$conn = odbc_pconnect($dsn, $user, $pass);
54+
var_dump(fetch_context_info($conn));
55+
56+
// run 3: close it and see if it's the same connection
57+
odbc_close($conn);
58+
$conn = odbc_pconnect($dsn, $user, $pass);
59+
var_dump(fetch_context_info($conn));
60+
61+
?>
62+
--EXPECTF--
63+
string(22) "PHP odbc_pconnect test"
64+
string(22) "PHP odbc_pconnect test"
65+
NULL

0 commit comments

Comments
 (0)