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!