Differences between execute and query methods in ThinkPHP _ PHP Tutorial

Source: Internet
Author: User
The difference between execute and query methods in ThinkPHP. In ThinkPHP, the execute () and query () methods can both directly input SQL statements in 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 () and query () in ThinkPHP such as select () you can directly enter SQL statements in 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 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 following are examples:

$ Model = M ("MyTable ");

$ Result = $ model-> execute ('select * from mytable'); // The total number of returned rows (number)

The query () method returns the dataset. if the query statement is incorrect or there is no query result, false is returned.

$ Result = $ model-> query ('select * from mytable'); // A two-dimensional result array or false is returned.

Articles you may be interested in
  • Use break, continue, goto, return, and exit in multiple loops in PHP
  • Differences and usage of return, exit, break, and contiue in PHP
  • Empty, is_null, and isset in php
  • Differences between echo, print, print_r, var_export, and var_dump in php
  • How to set the jump wait time for the thinkphp page jump (successerror)
  • How does thinkphp remove index. php from the url?
  • Differences between variables and functions in php after the static keyword is added
  • The last record of the volist loop in the thinkphp Template

The explain () and query () methods can both directly input SQL statements in 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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.