When I was a beginner at ThinkPHP, many people did not understand the differences between the execute () and query () methods. This article analyzes the differences between the two. For more information, see
When I was a beginner at ThinkPHP, many people did not understand the differences between the execute () and query () methods. This article analyzes the differences between the two. For more information, see
When I was a beginner at ThinkPHP, many people did not understand the differences between the execute () and query () methods. This article analyzes the differences between the two.
As we all know, the execute () and query () methods in ThinkPHP can both directly input SQL statements in parameters. However, execute () is usually used to execute SQL statements such as insert or update, while query is often used to execute select statements.
The execute () method returns the number of affected records. If you execute the select statement of SQL, the returned results will be the total number of records of the table:
The Code is as follows:
$ Model = M ("MyTable ");
$ Result = $ model-> execute ('Update MyTable set name = aaa where id = 11'); // The total number of rows returned
The query () method returns the dataset:
The Code is as follows:
$ Model = M ("MyTable ");
$ Result = $ model-> query ('select * from mytable'); // returns array ()
,