The difference between execute and query methods in thinkphp _php tutorial

Source: Internet
Author: User
Both the Execute () and the query () methods in thinkphp can enter SQL statements directly into the parameters. The difference is that execute () is typically used to execute SQL statements such as INSERT or update, and query is commonly used to execute statements such as SELECT. The Execute () method returns the number of records affected, and if you execute a SELECT statement for SQL, the result will be the total number of records for the table.

Here are a few specific examples to illustrate:

$model =m ("MyTable");

$result = $model->execute (' select * from MyTable '); Total row count (number) will be returned

The query () method returns the data set, which returns False if the queries are incorrect or if there are no query results

$result = $model->query (' select * from MyTable '); Will return a two-dimensional result array or false

Articles you may be interested in

    • Usage and differences in PHP that jump out of multiple loops using Break,continue,goto,return,exit
    • The difference and usage of return and exit, break and Contiue in PHP
    • PHP empty,is_null,isset The difference between the detailed
    • The usage and difference of echo,print,print_r,var_export,var_dump in PHP
    • thinkphp page Jump (successerror) How to set the jump wait time
    • thinkphp How to remove index.php from a URL
    • Differences in PHP after adding the static keyword to variables and functions
    • The last record in the thinkphp template that determines the volist loop

http://www.bkjia.com/PHPjc/764153.html www.bkjia.com true http://www.bkjia.com/PHPjc/764153.html techarticle both the Execute () and the query () methods in thinkphp can enter SQL statements directly into the parameters. The difference is that execute () is typically used to execute SQL statements such as INSERT or update, and query is commonly used to perform select and so on ...

  • 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.