亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP:如何在 MySQL 5.7 中保存二進制字符串

PHP:如何在 MySQL 5.7 中保存二進制字符串

PHP
慕標琳琳 2022-10-14 10:26:34
如何轉換此二進制字符串: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
查看完整描述

1 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

我解決了將所有表從 utf8 更改為 utf8mb4 的問題。并對字符串執行 utf8_encode(..)



查看完整回答
反對 回復 2022-10-14
  • 1 回答
  • 0 關注
  • 105 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號