How to get thinkphp framework last Execute SQL statement and variable debug

Source: Internet
Author: User
This article mainly introduces the thinkphp framework obtains the last execution SQL statement and the variable debugging simple operation, combined with the instance form analysis thinkphp obtains the last execution SQL statement getlastsql () and Fetchsql () function and the use of the Dump method variable debugging, E method output error information and other operational skills, the need for friends can refer to the following

This example describes the thinkphp framework to get the last execution of SQL statements and variable debugging simple operations. Share to everyone for your reference, as follows:

There are two ways to get the last SQL statement executed in thinkphp:

One is to call the model to get such as:

$sql = $model->getlastsql ();

Thinkphp model class, has getlastsql this function, even has, getlastinsid,getdberror,geterror,getpk,getdbfields and so on function. These functions are functions of the model layer that we can often use.

The second is the 3.2.3 version, which adds the Fetchsql () function.

Such as

$sql = $model->fetchsql (True)->add ($data);

A simplified approach can be used in version 3.2:

echo $model->_sql ();

Variable debugging

The thinkphp framework contains a browser-friendly dump method for outputting variable information to a browser view.

Usage:dump($var, $echo=true, $label=null, $strict=true)

$Blog = D ("Blog"), $blog = $Blog->find (3);d UMP ($blog);

You can use the E method to output error messages and break execution, for example:

Output error message, and Abort execution E ($msg);

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.