php - 仅对一个查询禁用 MySQL 严格模式 Laravel 5.6
问题描述
我只想为控制器内的一个查询禁用 MySQL 严格模式,而不是整个 laravel 应用程序,
我知道禁用 MySQL 严格模式的风险,所以我不想从 config/database.php 为我的整个应用程序禁用它,
我的整个应用程序中只有一个查询遇到问题,所以我想在我的控制器中禁用它,然后再运行一次该查询!
请帮助我在给定的情况下有什么办法。
解决方案
在运行时更改严格模式
config()->set('database.connections.mysql.strict', false);
\DB::reconnect(); //important as the existing connection if any would be in strict mode
Model::select()->get(); // your query called in non strict mode
//now changing back the strict ON
config()->set('database.connections.mysql.strict', true);
\DB::reconnect();
推荐阅读
- azure-stream-analytics - Azure 流分析 GetRecordPropertyValue 谜题
- javascript - jquery ajax删除请求删除一些但不是全部
- php - Laravel 资产文件 404
- javascript - Vue.js Emit event from Service
- python-3.x - By Beautiful Soup i scrape twitter data. I am able to get data but can't save in csv file
- javascript - XMLHTTPRequest inside forEach loop doesn't work
- c - 释放“struct”中用作“%union”模型的指针
- php - PHP Google API:如何获得更清晰的调试信息?
- multithreading - .NET Core 中的数据存储并行化
- scala - 有没有办法通过检查 Scala 中的 Array 元素来过滤 List 的元素?