[wp-trac] [WordPress Trac] #56877: dbDelta regex matches the incorrect Table/Database name as IF when using CREATE TABLE IF NOT EXISTS in the query

WordPress Trac noreply at wordpress.org
Fri Oct 21 12:30:38 UTC 2022


#56877: dbDelta regex matches the incorrect Table/Database name as IF when using
CREATE TABLE IF NOT EXISTS in the query
-----------------------------+-----------------------------
 Reporter:  sathyapulse      |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Upgrade/Install  |    Version:
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 The dbDelta function is used by plugins to create a custom table in the
 database. When the plugin uses the query that starts with `CREATE TABLE IF
 NOT EXISTS` or `CREATE DATABASE IF NOT EXISTS`, the regex matches the
 incorrect table or database name as `IF`.

 The function checks if the table exists using `DESCRIBE {$table};`. In
 this case, `DESCRIBE IF` produces a MySQL syntax error, but it's silently
 ignored, and the execution continues.

 It's not a major issue with the latest WordPress version and PHP 8.1
 because the [https://core.trac.wordpress.org/ticket/52825 MySQLi error
 reporting has been turned off since 5.9].

 It might produce a below fatal error with PHP 8.1 (because of
 [https://www.php.net/releases/8.1/en.php MySQLi error reporting change])
 and WordPress versions older than 5.9.


 {{{
 PHP Fatal error: Uncaught mysqli_sql_exception: You have an error in your
 SQL syntax; check the manual that corresponds to your MariaDB server
 version for the right syntax to use near 'IF
 }}}

 Regardless of MySQLi error reporting, it would be good to address the
 incorrect table/database name match.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56877>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list