当我尝试使用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')
...
我的问题是: 我如何设置" SET SQL_BIG_SELECTS = 1"在laravel查询?
答案 0 :(得分:4)
我找到了一个解决方案:)
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!
希望这对其他人有用;)