Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#56877 closed defect (bug) (duplicate)

dbDelta regex matches the incorrect Table/Database name as IF when using CREATE TABLE IF NOT EXISTS in the query

Reported by: sathyapulse's profile sathyapulse Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Upgrade/Install Keywords:
Focuses: Cc:

Description

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 MySQLi error reporting has been turned off since 5.9.

It might produce a below fatal error with PHP 8.1 (because of 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.

Attachments (1)

56877.diff (1.3 KB) - added by sathyapulse 2 years ago.

Download all attachments as: .zip

Change History (2)

@sathyapulse
2 years ago

#1 @SergeyBiryukov
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome back to WordPress Trac!

Thanks for the report, we're already tracking this in #41335.

Note: See TracTickets for help on using tickets.