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)".
The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.
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'); //将返回总行数
$model = M( "MyTable" ); $result = $model ->query( 'select * from MyTable' ); //将返回array()
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!