如何转换此二进制字符串:
b"iphonée@3,;= ÑÑñe x"
到普通字符串?
我真的需要将该字符串作为普通字符串,而不是作为二进制字符串。
我在 MySQL 中保存这个二进制字符串时遇到问题。如果我解码的 CSV 没有 ñ、é 或任何这些非常规字符,则保存没有问题。但是,当在单元格上设置其中一个字符时,该字符串似乎是二进制字符串,并且在 MySQL 上保存此二进制字符串时出现错误。
我收到此错误:
QueryException {#1780
#sql: "insert into `seller_product_languages` (`seller_product_id`, `lang`, `name`, `description`, `description_html`, `bullet_html`, `bullet`, `meta_keywords`, `default`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
#bindings: array:11 [
0 => 117
1 => "es"
2 => b"iphonée@3,;= ÑÑñe x"
3 => "negro"
4 => "negro"
5 => null
6 => ""
7 => null
8 => 1
9 => "2020-03-02 18:40:56"
10 => "2020-03-02 18:40:56"
]
#message: b"SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9e@3,;...' for column 'name' at row 1 (SQL: insert into `seller_product_languages` (`seller_product_id`, `lang`, `name`, `description`, `description_html`, `bullet_html`, `bullet`, `meta_keywords`, `default`, `updated_at`, `created_at`) values (117, es, iphonée@3,;= ÑÑñe x, negro, negro, , , , 1, 2020-03-02 18:40:56, 2020-03-02 18:40:56))"
#code: "HY000"
#file: "/home/vagrant/Code/PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
#line: 664
-previous: PDOException {#1779
#message: "SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9e@3,;...' for column 'name' at row 1"
#code: "HY000"
#file: "/home/vagrant/Code/PROJECT/vendor/laravel/framework/src/Illuminate/Database/Connection.php"
#line: 458
+errorInfo: array:3 [
0 => "HY000"
1 => 1366
2 => "Incorrect string value: '\xE9e@3,;...' for column 'name' at row 1"
]
所有表和列都是'utf8mb4'
和排序规则'utf8mb4_unicode_ci'
环境:-PHP 7.2 -Laravel 5.5 -Ubuntu 18.04 -MySQL 5.7