Home > Backend Development > PHP Tutorial > A brief analysis of the difference between execute and query methods in ThinkPHP_PHP Tutorial

A brief analysis of the difference between execute and query methods in ThinkPHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:28:20
Original
903 people have browsed it

When they first learn ThinkPHP, many people don't understand the difference between the execute() and query() methods. This article will briefly analyze the difference between the two.
As we all know, 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:

Copy code The code is as follows:
$model = M( "MyTable" );
$result = $model ->execute( 'update MyTable set name=aaa where id =11'); //The total number of rows will be returned

query() method will return the data set:
Copy code The code is as follows:
$model = M( "MyTable" );
$result = $model ->query( 'select * from MyTable' ); //array will be returned ()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/802214.htmlTechArticleWhen I first learned ThinkPHP, many people didn’t understand the difference between execute() and query() methods. This article Let’s briefly analyze the difference between the two. As we all know, both the execute() and query() methods in ThinkPHP can...
Related labels:
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