Method of using native MySQL statements in TP (code)

Source: Internet
Author: User
Tags mysql in
This article brings to you the content is about the use of the original MySQL in TP method (code), there is a certain reference value, the need for friends can refer to, I hope to help you.

Recently in the Thinkphp development project, want to use the native MySQL statement, finally tried, feel the corresponding complex query update operation, especially helpful! Below is the detailed introduction below!

1. Use native MySQL core

$Model = M ();        $result = $Model->query ($sql);//Query $model->execute ($sql _ex);//Update Modify Delete

2. Specific usage

  <?php    /**     * An acre of land * * Public    function Dealyimudi () {        $sql = "Select * from Yimudi y left JOIN Yimudi_us E yu on y.yimudi_id =yu.yimudi_id WHERE  yu.yimudi_id = All and Yu.use_status in (all) and y.use_end_time+86399 < UNI X_timestamp (now ()) ";        $Model = M ();        $result = $Model->query ($sql);        $yimudi _ids =[];        foreach ($result as $key = + $value) {            $yimudi _ids[] = $value [' id '];        }        foreach ($result as $key 1 = $value 1) {           if (In_array ($value 1[' id '), $yimudi _ids) {            $str _yimudi_id = $value 1 [' id '];            $sql _ex = "Update yimudi_use set use_status = 6 where id = ' $str _yimudi_id '";              $Model->execute ($sql _ex);           }        }        $result = $Model->query ($sql);        Dump ($result);d ie;    }

Everyone can try to use the next!

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.