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