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

不言
Release: 2023-04-01 08:20:01
Original
2162 people have browsed it

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();
Copy after login

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);
Copy after login

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)

<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;">echo $model-&gt;_sql();</pre><div class="contentsignin">Copy after login</div></div>You can use the E method to output error information and interrupt Execution, for example:

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

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template