Make WordPress Core

Opened 4 months ago

Last modified 10 days ago

#61338 new defect (bug)

wpdb::prepare function null value convert to empty String

Reported by: mazharul78's profile mazharul78 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Database Keywords: needs-patch
Focuses: Cc:

Description

In WordPress core, there is an issue where prepare functions null values convert to empty strings when interacting with the database. This causes problems for database table columns defined with NOT NULL constraints, leading to the insertion of empty strings instead of retaining null values.

Attachments (2)

table_column_structure.png (46.0 KB) - added by mazharul78 4 months ago.
The database table contains three columns: id, name, and email. The id column is an auto-increment primary key. The name column is nullable, meaning it can contain null values. The email column is set to not null, ensuring that it always contains a value.
inserted_empty_string.png (20.1 KB) - added by mazharul78 4 months ago.
The email column is not null, but inserting null into email results in an empty string.

Download all attachments as: .zip

Change History (3)

@mazharul78
4 months ago

The database table contains three columns: id, name, and email. The id column is an auto-increment primary key. The name column is nullable, meaning it can contain null values. The email column is set to not null, ensuring that it always contains a value.

@mazharul78
4 months ago

The email column is not null, but inserting null into email results in an empty string.

#1 @hellofromTonya
10 days ago

  • Version 6.6 deleted

Hello @mazharul78,

Welcome to WordPress Core's Trac.

I'm doing triage on bugs reported against WP 6.6.x as part of the 6.6.x minor / maintenance release cycle.

In reviewing wpdb::prepare(), I'm not finding any changes made to it during the 6.6 cycle. The only change made in the class was to remove back-compat support for database servers that don't support utf8mb4 (see #60096 / [57926]).

For now, I'll remove the Version, as I'm not finding that WP 6.6 introduced the issue.

Note: See TracTickets for help on using tickets.