Debugging methods required for using ThinkPHP

Source: Internet
Author: User

I often see people asking questions about the types of findAll returned data and the reasons for errors. I am still not familiar with the built-in debugging methods and methods of ThinkPHP, aside from the debugging methods provided by IDE, if you are using or planning to use ThinkPHP for development, you should understand and master the following methods related to debugging the Thinkphp program.

1. Open the debug mode DEBUG_MODE in the project configuration file, so that you can find most of the error causes. The output of the Verification Code may be affected.

2. If you do not want to use debug mode, you can enable page Trace display separately. The reason why many people do not want to use the debug mode is that there is output of page Trace information. In fact, there is a misunderstanding in this case that there must be page Trace in the debug mode, however, the debugging mode does not necessarily have to do with page Trace, because after the debugging mode is enabled, the system's default debugging configuration file will enable page Trace display, therefore, you can define the debugging configuration file for the project separately.

3. Using the system-defined dump function, this method is the same as var_dump, which can output any type of variable information, and is more conducive to viewing in the browser, for example:

$User=D("User");$list=$User->findAll();dump($list);

4. The 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 by ajax, therefore, you can enable the SQL log record SQL _DEBUG_LOG to record each SQL statement executed, and view the execution time of each SQL statement. The SQL log file is located under the Logs directory, the daily SQL logs are automatically distinguished by date.

5. If you suspect an SQL Execution error after executing a data operation, you can use the getLastSql method of the model class to view the last executed SQL statement to analyze the specific cause of the error. For example:

$ User = D ("User"); $ User-> id = 3; $ User-> name = 'thinkphp'; $ User-> save (); echo $ User-> getLastSql (); // The output result will be: update think_user set name = 'thinkphp' where id = 3;

6. When debugging the running time of a code segment, you can use the debug_start ($ label) and debug_end ($ label) methods provided by the system. For example:

Debug_start ('Demo'); // here is your code snippet... debug_end ('Demo ');
Articles you may be interested in
  • The last record of the volist loop in the thinkphp Template
  • How to set the jump wait time for the thinkphp page Jump (successerror)
  • Thinkphp prints the last SQL statement
  • Thinkphp automatic verification and automatic filling are invalid Solutions
  • Summary of system constants in the Action controller of thinkphp
  • Summary of Query Techniques in ThinkPHP
  • ThinkPHP built-in template engine usage Summary
  • Thinkphp Method for disabling caching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.