How to use native MySQL statements in TP (code)

不言
Release: 2023-04-03 20:58:02
Original
2740 people have browsed it

The content of this article is about the method (code) of using native MySQL statements in TP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Recently I was developing a project in Thinkphp and wanted to use native MySQL statements. I finally tried it and found it particularly helpful for complex query and update operations! Let’s introduce it in detail below!

1. Use the native mysql core

$Model = M(); $result = $Model->query($sql);//查询 $Model->execute($sql_ex);//更新修改删除
Copy after login

2. Specific usage

query($sql); $yimudi_ids =[]; foreach ($result as $key => $value) { $yimudi_ids[] =$value['id']; } foreach ($result as $key1 => $value1) { if(in_array($value1['id'],$yimudi_ids)){ $str_yimudi_id = $value1['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);die; }
Copy after login

You can try it!

Related recommendations:

Thinkphp upload class implements code for uploading images

How to use TP5.1 template loop tags (code)

The above is the detailed content of How to use native MySQL statements in TP (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
tp
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!