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!