Skip to content

Commit f2f1180

Browse files
authored
Merge pull request #212 from jonkerw85/master
Update ODBC connection validation for PHP 8.4 compatibility
2 parents 8096679 + 2f613d7 commit f2f1180

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ToolkitApi/Odbcsupp.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function connect($database, $user, $password, $options = null)
3737
$conn = odbc_connect($database, $user, $password);
3838
}
3939

40-
if (is_resource($conn)) {
40+
if ((version_compare(PHP_VERSION, '8.4.0', '<') && is_resource($conn)) ||
41+
(version_compare(PHP_VERSION, '8.4.0', '>=') && $conn instanceof \Odbc\Connection)) {
4142
return $conn;
4243
}
4344
}
@@ -51,7 +52,8 @@ public function connect($database, $user, $password, $options = null)
5152
*/
5253
public function disconnect($conn)
5354
{
54-
if (is_resource($conn)) {
55+
if ((version_compare(PHP_VERSION, '8.4.0', '<') && is_resource($conn)) ||
56+
(version_compare(PHP_VERSION, '8.4.0', '>=') && $conn instanceof \Odbc\Connection)) {
5557
odbc_close($conn);
5658
}
5759
}
@@ -168,7 +170,8 @@ public function executeQuery($conn, $stmt)
168170
$txt = array();
169171
$crsr = odbc_exec($conn, $stmt);
170172

171-
if (is_resource($crsr)) {
173+
if ((version_compare(PHP_VERSION, '8.4.0', '<') && is_resource($crsr)) ||
174+
(version_compare(PHP_VERSION, '8.4.0', '>=') && $crsr instanceof \Odbc\Result)) {
172175
while (odbc_fetch_row($crsr)) {
173176
$row = odbc_result($crsr, 1);
174177

ToolkitApi/Toolkit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ public function __construct($databaseNameOrResource, $userOrI5NamingFlag = '0',
285285
$this->debugLog("Created a new db connection in $durationCreate seconds.");
286286
}
287287

288-
if (!$conn) {
288+
if ((version_compare(PHP_VERSION, '8.4.0', '<') && !is_resource($conn)) ||
289+
(version_compare(PHP_VERSION, '8.4.0', '>=') && !($conn instanceof \Odbc\Connection))) {
289290
// Note: SQLState 08001 (with or without SQLCODE=-30082) usually means invalid user or password. This is true for DB2 and ODBC.
290291
$sqlState = $transport->getErrorCode();
291292
$this->error = $transport->getErrorMsg();

0 commit comments

Comments
 (0)