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 ()
http://www.bkjia.com/PHPjc/802214.htmlwww.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...