Both the execute() and query() methods in ThinkPHP can directly enter SQL statements in the parameters. 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 records affected. If the SQL select statement is executed, the returned result will be the total number of records in the table.
Here are some specific examples:
$model=M("MyTable");
$result=$model->execute('select * from MyTable'); //The total number of rows (number) will be returned
The query() method will return the data set. If the query statement is wrong or there is no query result, it will return false
$result=$model->query('select * from MyTable'); //Will return a two-dimensional result array or false
Articles you may be interested in
- The usage and difference of using break, continue, goto, return, exit to jump out of multiple loops in PHP
- The difference and usage of return and exit, break and contiue in PHP
- empty, Detailed explanation of the difference between is_null and isset
- Usage and difference of echo, print, print_r, var_export, var_dump in php
- How to set the jump waiting time for thinkphp page jump (successerror)
- thinkphp How to remove index.php from url
- The difference after adding static keyword before variables and functions in php
- The last record of volist loop in thinkphp template
http://www.bkjia.com/PHPjc/764153.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764153.htmlTechArticleBoth the execute() and query() methods in ThinkPHP can directly enter SQL statements in the parameters. The difference is that execute() is usually used to execute SQL statements such as insert or update, while query is often used to execute select, etc...
Statement: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