In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to catch mysql errors in larval, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Larval captures mysql errors: 1. Use the errorInfo variable to return SQLSTATE errors and messages; 2. Use the exception handler "app/Exceptions/Handler.php and listen for QueryExceptions" to log all SQL errors to data.
Laravel uses PDO, so you can use the errorInfo variable to return SQLSTATE errors and messages. Basically, you need to use $e-> errorInfo
If you want to log all SQL errors to the database, you can use the exception handler (app/Exceptions/Handler.php) and listen for QueryExceptions. Something like this:
Public function render ($request, Exception $e) {switch ($e) {case ($e instanceof\ Illuminate\ Database\ QueryException): LogTracker::saveSqlError ($e); break; default: LogTracker::saveError ($e, $e-> getCode ());} return parent::render ($request, $e);}
And then you can use something like this:
Public function saveSqlError ($exception) {$sql = $exception- > getSql (); $bindings = $exception- > getBindings () / / Process the query's SQL and parameters and create the exact query foreach ($bindings as $I = > $binding) {if ($binding instanceof\ DateTime) {$bindings [$] = $binding- > format ('\ 'Y-m-d H:i:s\') } else {if (is_string ($binding)) {$bindings [$] = "'$binding'";} $query = str_replace (array ('%','?), array ('%','% s'), $sql); $query = vsprintf ($query, $bindings); / / Here's the part you need $errorInfo = $exception- > errorInfo $data = ['sql' = > $query,' message' = > isset ($errorInfo [2])? $errorInfo [2]:', 'sql_state' = > $errorInfo [0],' error_code' = > $errorInfo [1]]; / / Now store the error into database, if you want.. / /.} Thank you for reading this article carefully. I hope it is helpful for everyone to share how to capture mysql errors in larval. At the same time, I also hope that you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.