繁体   English   中英

SQLSTATE[22007]:无效的日期时间格式:1366 字符串值不正确,html_entity_decode function

[英]SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value, html_entity_decode function

我一直在尝试 html_entity_decode 如下;

//Foreach ($datas from remote db)
$recorded = User::updateOrCreate([
        "old_id" => $user->Id,
        "username" => $user->UserName,
    ],[
        "old_id" => $user->Id,
        "name" => html_entity_decode($user->FullName),
        "username" => $user->UserName
]

它给了我一个如下错误,

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xE3\xBCseyi...' for
column `database`.`users`.`name` at row 1 (SQL: update `users` set
`name` = hseyin furkan, `users`.`updated_at` = 2021-02-22 18:23:39 where `id` = 2)

如果我不调用html_entity_decode function,它会写入像“hüseyin”这样的列

我该如何解决?

我的桌子:

Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name')->nullable();
        $table->string('username')->nullable();

可能,你的数据是ASCII字符集,你的列等待UTF-8 可以试试这个代码吗;

mb_convert_encoding(html_entity_decode($user->FullName), "UTF-8")

如果你使用laravel,你可以使用function那个;

$fullname = Str::ascii(html_entity_decode($user->FullName),'tr');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM