When beginners thinkphp, many people do not understand the difference between execute () and the query () method, this article analyzes the difference between the two.
As you know, both the Execute () and the query () methods in thinkphp can enter SQL statements directly into the parameters. But the difference is
execute () is typically used to execute SQL statements such as INSERT or update, while
query is used to execute statements such as SELECT。
The Execute () method returns the number of records affected, if you execute a SELECT statement for SQL, the result will be the total number of records for the table:
Copy CodeThe 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
the query () method returns the data set:
Copy CodeThe code is as follows: $model = M ("MyTable");
$result = $model->query (' select * from MyTable '); Returns an array ()
http://www.bkjia.com/PHPjc/802214.html www.bkjia.com true http://www.bkjia.com/PHPjc/802214.html techarticle when beginners thinkphp, many people do not understand the difference between execute () and the query () method, this article analyzes the difference between the two. As you all know, the Execute () and the query () methods in thinkphp are available ...