From b8661ea2678995ec7a0efeb05e1dadcc957194fd Mon Sep 17 00:00:00 2001 From: ReimuHakurei Date: Fri, 6 May 2022 04:41:03 -0500 Subject: pgsql: remove is_resource() checks (PHP 8.1 compat) Affected_Rows() always returns false on PHP 8.1, because the 'pgsql result' resource has been replaced by the PgSql\Result class [1]. Changes to original contribution: * Adjust PHPDoc for ADODB_postgres64::$_resultid * Fix one more occurrence in the postgres7 driver Fixes #833 [1]: https://www.php.net/manual/en/class.pgsql-result.php Co-authored-by: Damien Regad (cherry picked from commit e3287d6be5545634a6ccbf868919028991a68791) --- drivers/adodb-postgres64.inc.php | 12 +++++------- drivers/adodb-postgres7.inc.php | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/adodb-postgres64.inc.php b/drivers/adodb-postgres64.inc.php index 525e09d2..290967e7 100644 --- a/drivers/adodb-postgres64.inc.php +++ b/drivers/adodb-postgres64.inc.php @@ -26,7 +26,7 @@ class ADODB_postgres64 extends ADOConnection{ var $databaseType = 'postgres64'; var $dataProvider = 'postgres'; var $hasInsertID = true; - /** @var bool|resource */ + /** @var PgSql\Connection|resource|false */ var $_resultid = false; var $concat_operator='||'; var $metaDatabasesSQL = "select datname from pg_database where datname not in ('template0','template1') order by 1"; @@ -155,7 +155,7 @@ class ADODB_postgres64 extends ADOConnection{ */ protected function _insertID($table = '', $column = '') { - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; + if ($this->_resultid === false) return false; $oid = pg_last_oid($this->_resultid); // to really return the id, we need the table and column-name, else we can only return the oid != id return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid); @@ -163,7 +163,7 @@ class ADODB_postgres64 extends ADOConnection{ function _affectedrows() { - if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false; + if ($this->_resultid === false) return false; return pg_affected_rows($this->_resultid); } @@ -844,7 +844,7 @@ class ADODB_postgres64 extends ADOConnection{ } // check if no data returned, then no need to create real recordset if ($rez && pg_num_fields($rez) <= 0) { - if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') { + if ($this->_resultid !== false) { pg_free_result($this->_resultid); } $this->_resultid = $rez; @@ -1075,9 +1075,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{ function _close() { - if (!is_resource($this->_queryID) - || get_resource_type($this->_queryID) != 'pgsql result' - ) { + if ($this->_queryID === false) { return true; } return pg_free_result($this->_queryID); diff --git a/drivers/adodb-postgres7.inc.php b/drivers/adodb-postgres7.inc.php index ddbe7a6e..b5e63acf 100644 --- a/drivers/adodb-postgres7.inc.php +++ b/drivers/adodb-postgres7.inc.php @@ -231,7 +231,7 @@ class ADODB_postgres7 extends ADODB_postgres64 { } // check if no data returned, then no need to create real recordset if ($rez && pg_num_fields($rez) <= 0) { - if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') { + if ($this->_resultid !== false) { pg_free_result($this->_resultid); } $this->_resultid = $rez; -- cgit v1.3