In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you the difference between execute () and query () in ThinkPHP. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Both the execute () and query () methods in ThinkPHP can enter SQL statements directly 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 returns the number of records affected, and if the select statement of SQL is executed, the result will be the total number of records in the table:
$model = M ("MyTable")
$result = $model-> execute ('select * from MyTable'); / / the total number of rows will be returned
The total number of rows returned by execute is similar to that in native php.
$sql = 'select `status` from `sys_ serinfo` where `status` = 1'
$query = mysql_query ($sql)
$result = mysql_num_rows ($query)
/ / mysql_num_rows from manual returns the number of rows in the result set. This command is valid only for SELECT statements.
Echo $result
The query () method returns the dataset:
$model = M ("MyTable")
$result = $model-> query ('select * from MyTable'); / / array () will be returned
Execute () is mainly used for updates and writes, and execute () is used for the number of affected rows but no result set; there is no need to return the pending value from the database.
Query () is mainly used to query the number of affected rows and result sets to get the data that needs to be processed from the database.
-
What is the difference between execute () and query () in ThinkPHP? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.