In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what debugging means you should master when using ThinkPHP. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Debugging methods that should be mastered in using ThinkPHP
We often see people asking questions such as what the return data type of findAll is, and I don't know why something went wrong. In fact, I am still not familiar with the built-in debugging methods and methods of ThinkPHP. Apart from the debugging methods that come with IDE itself, if you are using or planning to develop with ThinkPHP, there are some debugging-related methods that you should know and master:
1. Open debug mode DEBUG_MODE in the project configuration file, which allows you to find most of the causes of errors. May affect the output of the CAPTCHA.
2. If you do not want to use debug mode, you can open the page Trace display separately. Found that many people do not want to use debug mode is unexpectedly because there is a page Trace information output, in fact, there is a misunderstanding, that debug mode must have page Trace, but in fact debug mode and page Trace there is no inevitable relationship, just because after opening debug mode, the system default debug configuration file will open the page Trace display, so you can define a debug configuration file for the project separately.
3. Use the system-defined dump function, which, like var_dump, can output variable information of any type, and is more convenient to view in the browser, for example:
The code is as follows:
$User = D ("User"); $list = $User- > findAll (); dump ($list)
4. Page Trace information can only display the sql statements executed on the current page, but cannot view the sql statements in the background operations executed in ajax mode, so you can also open sql log recording SQL_DEBUG_LOG to record each execution of sql statements, and you can see that the execution time of each sql statement sql log file is located in the Logs directory, which will automatically distinguish the daily sql log by date.
5. The other is that if it is suspected that there is an error in sql execution after performing a data operation, you can use the getLastSql method of the model class to view the last executed sql statement in order to analyze the specific cause of the error. For example:
The code is as follows:
$User = D ("User"); $User- > id=3; $User- > name = 'ThinkPHp';$User- > save (); echo $User- > getLastSql (); / / output update think_user set where id=3
6. When you need to debug the run time of a piece of code, you can use the debug_start ($label) and debug_end ($label) methods provided by the system, for example:
The code is as follows:
Debug_start ('demo'); / / here is your code snippet. Debug _ end (' demo'); this is the end of the article on "what debugging methods you should master when using ThinkPHP". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.