Home >Backend Development >PHP Tutorial >How to obtain the last executed SQL statement and variable debugging of the ThinkPHP framework

How to obtain the last executed SQL statement and variable debugging of the ThinkPHP framework

不言
不言Original
2018-06-14 15:31:542206browse

This article mainly introduces the simple operations of the ThinkPHP framework to obtain the last executed SQL statement and variable debugging. It analyzes the getLastSql() and fetchSql() functions of thinkPHP to obtain the last executed SQL statement and uses the dump method to debug variables in the form of examples. , E method outputs error information and other operation skills, friends in need can refer to the following

This article describes the simple operation of the ThinkPHP framework to obtain the last executed SQL statement and variable debugging. Share it with everyone for your reference, the details are as follows:

There are two ways to get the last executed sql statement in ThinkPHP:

One It is to call the model to obtain, such as:

$sql = $model ->getLastSql();

Model class in Thinkphp, there is the function getLastSql, and there are even functions such as getLastInsID, getDbError, getError, getPk, getDbFields and other functions. These functions are model layer functions that we may often use.

The second is that in version 3.2.3, the fetchSql() function is added.

For example, in version 3.2, a simplified method can be used:

$sql= $model->fetchSql(true)->add($data);

Variable debugging The ThinkPHP framework has a built-in browser-friendly dump method for outputting variable information to the browser for viewing.

Usage:

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

<pre class="brush:php;toolbar:false;">echo $model-&gt;_sql();</pre>You can use the E method to output error information and interrupt Execution, for example:

$Blog = D("Blog");
$blog = $Blog->find(3);
dump($blog);

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How thinkPHP framework implements multi-table queries

##About thinkPHP framework multi-layer controllers and multi-level controllers use

The above is the detailed content of How to obtain the last executed SQL statement and variable debugging of the ThinkPHP framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn