Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#34585 closed defect (bug) (invalid)

Updating via $wpdb->update fails when using Chinese Characters, depending on the characters postion in the string

Reported by: while1's profile while1 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Database Keywords:
Focuses: Cc:

Description

Update Fails for:

<?php
$wpdb->update($table, array('value' => $struct_title,'xml_data' => $data,),array('ID' => $update_id));

no Update in Database. But is working using $wpdb->prepared():

<?php
$wpdb->query($wpdb->prepare("UPDATE $table SET xml_data=%s WHERE ID='$update_id' ",$data));

I guess it's a encoding/transfer problem in the WP-Database Layer when using $wpdb->update().

  • All UTF-8 / also used UTF-8 Fix Iconv from W3C.
  • pasting the same string in PHPMyAdmin works

for more information or a source code to a test case feel free to contact me.

I Attached File with a text string reproducing the bug. Moving the Chinese characters by new spaces or regular characters makes the string work in $wdpd->update or not.

for now the $wpdb->query solution works for me but i prefer using the $wpdb->update method.

Attachments (1)

hazardous_string.txt (1.7 KB) - added by while1 9 years ago.
The string that breaks the query while updating with $wpdb->update

Download all attachments as: .zip

Change History (5)

@while1
9 years ago

The string that breaks the query while updating with $wpdb->update

#1 @dd32
9 years ago

Hi @while1,

Welcome to Trac :)

Can you please verify and post what charset you have defined in wp-config.php (DB_CHARSET) and what the database tables are set to? (utf8? utf8mb4?)

#2 @while1
9 years ago

Hi There,

For the original Wordpress Tables:

  • utf8mb4_unicode_ci

For our production tables, the ones wich are affected, i use

  • utf8_general_ci

the wp-config.php setting is set to:

  • define('DB_CHARSET', 'utf8');

The Website and Formulars are all set to

  • UTF8

I didn't try to set the Encoding of our tables to utf8mb4_unicode_cim yet. Should i?
We are handling ALL possible languages in our systems and already spent a lot of time internally into encoding compatibility issues but never needed to fix a thing on WP-Core side.

I also saw your Video Annoucement some month ago when you explained the WP-Core Update to UTF8mb4. And the reasons why you didi this. Let me say, In general i am very satisfied with the WP-Core database. Using it massively for the last 1.5 Years, never had any problems. The speed is quite good.

#3 @while1
9 years ago

  • Resolution set to invalid
  • Status changed from new to closed

I cleared up the problem - it was my own fault and is not related to the WP-Core-DB Layer. Sorry for that.

I also updated a second field with the same query, with a substringed an striptagged version of the long string. i used a substr and not mb_substr in this case to shorten the string - leading to toxic UTF-8 multibyte Characters in the query which then should fail.

Sorry for using up your time i am happy that there is no bug inside the WP-Core.
Thanks for your time, i really enjoy using your software.

#4 @netweb
9 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.