execute(SQL statement)"."/> execute(SQL statement)".">

Home  >  Article  >  PHP Framework  >  What is the usage of execute in thinkphp

What is the usage of execute in thinkphp

WBOY
WBOYOriginal
2022-02-18 15:46:503292browse

In thinkphp, the execute() method can directly enter SQL statements in the parameters. This method is used to execute SQL statements such as insert or update. The returned result is the number of records affected by the SQL statement. The syntax is "$ model ->execute(SQL statement)".

What is the usage of execute in thinkphp

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

What is the usage of execute in thinkphp

Both the execute() and query() methods in ThinkPHP can directly enter SQL statements in the parameters. But the difference is that execute() is usually used to execute SQL statements such as insert or update, while query is often used to execute statements such as select.

The execute() method will return the number of affected records. If the SQL select statement is executed, the returned result will be the total number of records in the table:

The code is as follows:

$model = M( "MyTable" );
$result = $model ->execute( 'update MyTable set name=aaa where id=11'); //将返回总行数
# The ##query() method will return the data set:

The code is as follows:

$model = M( "MyTable" );
$result = $model ->query( 'select * from  MyTable' ); //将返回array()

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What is the usage of execute in thinkphp. 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