[wp-trac] [WordPress Trac] #52825: [PHP 8.1] MySQLi error reporting value changes

WordPress Trac noreply at wordpress.org
Sun Aug 8 14:08:29 UTC 2021


#52825: [PHP 8.1] MySQLi error reporting value changes
------------------------------------------+---------------------
 Reporter:  ayeshrajans                   |       Owner:  jrf
     Type:  defect (bug)                  |      Status:  closed
 Priority:  normal                        |   Milestone:  5.9
Component:  Database                      |     Version:
 Severity:  normal                        |  Resolution:  fixed
 Keywords:  php81 has-patch commit early  |     Focuses:
------------------------------------------+---------------------
Changes (by SergeyBiryukov):

 * status:  accepted => closed
 * resolution:   => fixed


Comment:

 In [changeset:"51582" 51582]:
 {{{
 #!CommitTicketReference repository="" revision="51582"
 Code Modernization: Set the MySQLi error reporting off for PHP 8.1.

 Prior to PHP 8.1, the default error handling mode was `MYSQLI_REPORT_OFF`.
 An error in the extension, database, query, or the database connection
 returned `false` and emitted a PHP warning:
 {{{
 $mysqli = new mysqli("localhost", "non-existing-user", "", "");

 Warning: mysqli::__construct(): (HY000/2002): No connection could be made
 because the target machine actively refused it in ... on line ...
 }}}

 From PHP 8.1 and later, the default error mode is set to
 `MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT`. An error in the extension,
 database, query, or the database connection throws an exception:
 {{{
 $mysqli = new mysqli("localhost", "non-existing-user", "", "");

 Fatal error: Uncaught mysqli_sql_exception: Connection refused in ...:...
 }}}

 WordPress has its own error reporting and gracefully handles the database
 errors by inspecting the error codes. Setting the MySQLi error reporting
 to off avoids fatal errors due to uncaught exceptions and maintains the
 current behavior.

 References:
 * [https://php.watch/versions/8.1/mysqli-error-mode PHP 8.1: MySQLi:
 Default error mode set to exceptions]
 * [https://wiki.php.net/rfc/mysqli_default_errmode PHP RFC: Change Default
 mysqli Error Mode]

 Props ayeshrajans, jrf.
 Fixes #52825.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52825#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list