Skip to content

Commit

Permalink
Merge pull request #212 from jonkerw85/master
Browse files Browse the repository at this point in the history
Update ODBC connection validation for PHP 8.4 compatibility
  • Loading branch information
alanseiden authored Jan 13, 2025
2 parents 8096679 + 2f613d7 commit f2f1180
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions ToolkitApi/Odbcsupp.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function connect($database, $user, $password, $options = null)
$conn = odbc_connect($database, $user, $password);
}

if (is_resource($conn)) {
if ((version_compare(PHP_VERSION, '8.4.0', '<') && is_resource($conn)) ||
(version_compare(PHP_VERSION, '8.4.0', '>=') && $conn instanceof \Odbc\Connection)) {
return $conn;
}
}
Expand All @@ -51,7 +52,8 @@ public function connect($database, $user, $password, $options = null)
*/
public function disconnect($conn)
{
if (is_resource($conn)) {
if ((version_compare(PHP_VERSION, '8.4.0', '<') && is_resource($conn)) ||
(version_compare(PHP_VERSION, '8.4.0', '>=') && $conn instanceof \Odbc\Connection)) {
odbc_close($conn);
}
}
Expand Down Expand Up @@ -168,7 +170,8 @@ public function executeQuery($conn, $stmt)
$txt = array();
$crsr = odbc_exec($conn, $stmt);

if (is_resource($crsr)) {
if ((version_compare(PHP_VERSION, '8.4.0', '<') && is_resource($crsr)) ||
(version_compare(PHP_VERSION, '8.4.0', '>=') && $crsr instanceof \Odbc\Result)) {
while (odbc_fetch_row($crsr)) {
$row = odbc_result($crsr, 1);

Expand Down
3 changes: 2 additions & 1 deletion ToolkitApi/Toolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public function __construct($databaseNameOrResource, $userOrI5NamingFlag = '0',
$this->debugLog("Created a new db connection in $durationCreate seconds.");
}

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

0 comments on commit f2f1180

Please sign in to comment.