diff options
| author | Damien Regad <dregad@mantisbt.org> | 2021-03-08 18:32:52 +0100 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2021-03-08 18:32:52 +0100 |
| commit | def710065bb2b5d351a0d13b9859cf4b1334787a (patch) | |
| tree | 74f06c19dc30f037f654eca31ce11909f145b1d9 | |
| parent | f60a161ee06a9daba2a72ea7dd3591285ace45b0 (diff) | |
| download | adodb-def710065bb2b5d351a0d13b9859cf4b1334787a.tar.gz adodb-def710065bb2b5d351a0d13b9859cf4b1334787a.tar.bz2 adodb-def710065bb2b5d351a0d13b9859cf4b1334787a.zip | |
get/setCharSet: avoid TypeError when no connection
On mysqli, PHP 8 throws an 'Uncaught TypeError: method_exists():
Argument 1 ($object_or_class) must be of type object|string, bool
given'. Checking that _connectionID is set fixes the problem.
A similar issue was found and fixed with the postgres7 driver as well.
Note that fixing the legacy mysql driver is not necessary, as the driver
has been removed in PHP 7, and the error suppression operator should do
the job on PHP 5.
Fixes #686
| -rw-r--r-- | docs/changelog.md | 10 | ||||
| -rw-r--r-- | drivers/adodb-mysqli.inc.php | 8 | ||||
| -rw-r--r-- | drivers/adodb-postgres7.inc.php | 4 |
3 files changed, 17 insertions, 5 deletions
diff --git a/docs/changelog.md b/docs/changelog.md index 0b8429f8..b5dff341 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -14,6 +14,14 @@ Older changelogs: -------------------------------------------------------------------------------- +## [Unreleased] + +### Fixed + +- mysql: TypeError when calling get/setChangeSet on unset connection (PHP 8) + [#686](https://github.com/ADOdb/ADOdb/issues/686) + + ## [5.21.0] - 2021-02-27 ### Fixed @@ -1054,6 +1062,8 @@ Released together with [v4.95](changelog_v4.x.md#495---17-may-2007) - Adodb5 version,more error checking code now will use exceptions if available. +[Unreleased]: https://github.com/adodb/adodb/compare/v5.21.0...hotfix/5.21 + [5.21.0]: https://github.com/adodb/adodb/compare/v5.21.0-rc.1...v5.21.0 [5.21.0-rc.1]: https://github.com/adodb/adodb/compare/v5.21.0-beta.1...v5.21.0-rc.1 [5.21.0-beta.1]: https://github.com/adodb/adodb/compare/v5.20.20...v5.21.0-beta.1 diff --git a/drivers/adodb-mysqli.inc.php b/drivers/adodb-mysqli.inc.php index c2415163..9c98fb9a 100644 --- a/drivers/adodb-mysqli.inc.php +++ b/drivers/adodb-mysqli.inc.php @@ -1175,13 +1175,13 @@ class ADODB_mysqli extends ADOConnection { function getCharSet() { - //we will use ADO's builtin property charSet - if (!method_exists($this->_connectionID,'character_set_name')) + if (!$this->_connectionID || !method_exists($this->_connectionID,'character_set_name')) { return false; + } $this->charSet = @$this->_connectionID->character_set_name(); if (!$this->charSet) { - return false; + } else { return $this->charSet; } @@ -1189,7 +1189,7 @@ class ADODB_mysqli extends ADOConnection { function setCharSet($charset) { - if (!method_exists($this->_connectionID,'set_charset')) { + if (!$this->_connectionID || !method_exists($this->_connectionID,'set_charset')) { return false; } diff --git a/drivers/adodb-postgres7.inc.php b/drivers/adodb-postgres7.inc.php index 2cfe694d..38762bf3 100644 --- a/drivers/adodb-postgres7.inc.php +++ b/drivers/adodb-postgres7.inc.php @@ -280,7 +280,9 @@ class ADODB_postgres7 extends ADODB_postgres64 { */ function getCharSet() { - //we will use ADO's builtin property charSet + if (!$this->_connectionID) { + return false; + } $this->charSet = @pg_client_encoding($this->_connectionID); if (!$this->charSet) { return false; |
