zf1s / zf1

Monorepo of a fork of Zend Framework 1, with all components split into individual composer packages. PHP 5.3-8.3 compatible.
BSD 3-Clause "New" or "Revised" License
57 stars 22 forks source link

[zend-db] fix MySQLi adapter after changing default reporting mode by PHP 8.1 #156

Closed partikus closed 1 year ago

partikus commented 1 year ago

In PHP 8.1, the default error handling behavior of the MySQLi extension has changed from silencing errors to throw an Exception on errors.

MySQLi's default error mode is changed from MYSQLI_REPORT_OFF to MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT

https://php.watch/versions/8.1/mysqli-error-mode https://www.php.net/manual/en/class.mysqli-sql-exception.php

There were 2 ways how to solve it:

  1. reverting MYSQLI_REPORT_OFF when no special config is given
    if (!isset($this->_config['report_mode']) || PHP_VERSION_ID >= 80100) {
        mysqli_report(
            isset($this->_config['report_mode'])
                ? $this->_config['report_mode']
                : MYSQLI_REPORT_OFF
        );
    }
  2. wrapping all possible places where an exception can be thrown with try/catch

I've chosen 2nd option taking inspiration from https://github.com/doctrine/dbal/pull/4875/

After adjusting MySQLi stuff we ended with:

There were 22 incomplete tests: ...
There were 591 skipped tests:  ...

No errors, failures for PHP 8.1.

falkenhawk commented 1 year ago

Thanks @partikus ! Please adjust the PR title to reflect the issue what it is really addressing. Tests are not being adjusted at all in this PR.

partikus commented 1 year ago

@falkenhawk updated, thank you for your comments 👍