Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 插入表情时插入语句有效,但使用雄辩时抛出错误_Php_Mysql_Laravel_Eloquent - Fatal编程技术网

Php 插入表情时插入语句有效,但使用雄辩时抛出错误

Php 插入表情时插入语句有效,但使用雄辩时抛出错误,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,运行查询时 插入到表中(参考号、用户号、角色号、文本) 值(233,3,40,'hdhdh)由于问题: 默认情况下,Laravel使用utf8作为MySQL的字符集。在MySQL中,utf8字符最长为3字节(utf8是utf8mb3的别名)。而表情符号最长为4字节 因此,我们需要使用utf8mb4作为我们的字符集 解决方案: 1.打开您的config/database.php 2.查找MySQL部分: 'mysql' => [ 'driver' => 'mysql',

运行查询时

插入到表中(参考号、用户号、角色号、文本)
值(233,3,40,'hdhdh)由于问题:
默认情况下,Laravel使用
utf8
作为MySQL的字符集。在MySQL中,utf8字符最长为3字节(
utf8
utf8mb3
的别名)。而表情符号最长为4字节

因此,我们需要使用
utf8mb4
作为我们的字符集

解决方案: 1.打开您的
config/database.php

2.查找MySQL部分:

'mysql' => [
    'driver' => 'mysql',
    [...]
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    [....]
'mysql' => [
    'driver' => 'mysql',
    [...]
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    [....]
3.将字符集、排序规则分别更改为
utf8mb4
utf8mb4\u unicode\u ci

'mysql' => [
    'driver' => 'mysql',
    [...]
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    [....]
'mysql' => [
    'driver' => 'mysql',
    [...]
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    [....]
4.保存并重置数据库:

'mysql' => [
    'driver' => 'mysql',
    [...]
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    [....]
'mysql' => [
    'driver' => 'mysql',
    [...]
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    [....]
请注意,如果重置数据库,所有数据都将被删除

php artisan迁移:重置


也许司机的字符集错了?