gpt4 book ai didi

php - 如何在 Laravel 中加入 "SET SQL_BIG_SELECTS=1"语句

转载 作者:行者123 更新时间:2023-11-29 04:18:10 25 4
gpt4 key购买 nike

当我尝试使用 6 个连接执行数据库查询时,我收到以下错误消息:

SQLSTATE[42000]: Syntax error or access violation: 1104 The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay

 $results = DB::table('table_1')
->join('table_2', 'table_1.id', '=', 'table_2.id')

...

我的问题是:如何在 Laravel 查询中设置“SET SQL_BIG_SELECTS=1”?

最佳答案

我找到了一个解决方案:)

in app/config/database.php

更改以下内容:

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],

收件人:

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET SESSION SQL_BIG_SELECTS=1',
),
'strict' => false,
],

我添加了“选项”数组并定义了 SQL_BIG_SELECTS

就是这样,我们可以按照我们需要的任何方式配置 PDO!

希望这对其他人有用;)

关于php - 如何在 Laravel 中加入 "SET SQL_BIG_SELECTS=1"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34853129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com