当前位置:网站首页>PHP realizes data interaction with MySQL
PHP realizes data interaction with MySQL
2022-07-27 08:02:00 【Shenzhi Kalan Temple】
PHP Is a powerful server-side scripting language for creating dynamic interactive sites
MySQL Is the most popular relational database management system , Especially WEB Application is very important
So how do these two interact , The method is as follows :

The following is a brief description of a simple hotel module business control on and off php call mysql
PHP call MySQL Insert data into
Add hotel information
<?php
/*
* The front end can call this php Script adds hotel room information , The corresponding table is dwd_hotel_module_baseinfo
s_hotel_id int comment ' The hotel ID' ,
s_hotel_name varchar(50) comment ' Hotel name ',
*/
// These variables are the values passed in by the front end
$s_hotel_id = $_POST["s_hotel_id"];
$s_hotel_name = $_POST["s_hotel_name"];
// Fill in the database information here
$conn=mysqli_connect("localhost","root","passwd1","database1");
// Detection connection
if (mysqli_connect_errno())
{
echo " The connection fails : " . mysqli_connect_error();
}
// The integer type is ".$number." The character type is '".$string."'
$sql = "INSERT INTO dwd_hotel_module_baseinfo(s_hotel_id,s_hotel_name)
VALUES (".$s_hotel_id.",'".$s_hotel_name."')";
if ($conn->query($sql) === TRUE) {
echo " New record inserted successfully ";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>PHP call MySQL Data update
Control power on and off by changing the field value
<?php
/*
* The front end can call this php Script to control power on ,ads_module_onoff_switch,
s_module_id varchar(20) primary key comment ' modular ID',
n_status bigint comment ' Power on switch control 0 Delegate energized ,1 It means no electricity '
*/
// These variables are the values passed in by the front end
$s_module_id = $_POST["s_module_id"];
$n_status = $_POST["n_status"];
// Fill in the database information here
$conn=mysqli_connect("localhost","root","passwd1","database1");
// Detection connection
if (mysqli_connect_errno())
{
echo " The connection fails : " . mysqli_connect_error();
}
mysqli_query($conn,"UPDATE ads_module_onoff_switch SET n_status = ".$n_status."
WHERE s_module_id= ".$s_module_id." ");
mysqli_close($conn);
?>PHP call MySQL Return the data (JSON type )
php call mysql Data and return json Data to front end
<?php
/*
* The front end can call this php Script to get the power on status of the module , The duration of power on ,dws_hotel_module_day_status,
s_module_id varchar(20) primary key comment ' modular ID',
n_status int comment ' adopt ads_module_onoff_switch relation ',
n_eleuse_long double comment ' The duration of power on , when ',
n_date int comment ' Date of the day '
*/
// These variables are the values passed in by the front end
$s_module_id = $_POST["s_module_id"];
$n_date = date('Ymd', time());
// Fill in the database information here
$conn=mysqli_connect("localhost","root","passwd1","database1");
// Detection connection
if (mysqli_connect_errno()) {
echo " The connection fails : " . mysqli_connect_error();
}
$result1 = mysqli_query($conn, "SELECT case when n_status = 1 then ' Electrify ' else ' power failure ' end as n_status FROM ads_module_onoff_switch
where s_module_id = '".$s_module_id."' ");
while ($row = mysqli_fetch_array($result1)) {
$n_status = $row['n_status'];
}
$result2 = mysqli_query($conn, "SELECT round(sum(n_eleconn_long)/3600,2) as long1 FROM table1
where s_module_id = '".$s_module_id."' and FROM_UNIXTIME(n_eledisconn_time,'%Y%m%d')= '".$n_date."'");
while ($row = mysqli_fetch_array($result2)) {
$n_eleuse_long = $row['long1'];
}
//header('Content-Type:application/json; charset=utf-8');
$arr = array('s_module_id'=>$s_module_id,'n_status'=>$n_ele_status,'n_eleuse_long'=>$n_eleuse_long,'n_date'=>$n_date);
# return json Data is used by the front end
exit(json_encode($arr,JSON_UNESCAPED_UNICODE));
$conn->close();
?>
I like you , It's my exclusive memory
边栏推荐
- 反弹shell是什么?反弹shell有什么用?
- The first open source MySQL native HTAP database in China will be released soon! Look at the three highlights first, limited to the surrounding areas, waiting for you~
- 【已解决】单点登录成功SSO转发,转发URL中带参数导致报错There was an unexpected error (type=Internal Server Error, status=500)
- slf4j如何进行logback配置呢?
- 如何获取广告服务流量变现数据,助力广告效果分析?
- 大家节日快乐哈
- 【万字长文】吃透负载均衡,和阿里大牛的技术面谈
- 数据库启动报error_user_connect_times &gt; 0错误
- 剑指 Offer 58 - I. 翻转单词顺序
- C commissioned use cases
猜你喜欢

MCU multi-level menu

数据提取2

A quick overview of transformer quantitative papers in emnlp 2020

Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money
![[applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP](/img/0c/da2ffc00834793c7abc0f7ebe6321b.png)
[applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP

综合案例、

Stored procedures and functions
![[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel](/img/fc/1ee8b77d675e34da2eb8574592c489.png)
[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel

Happy holidays, everyone

What are the software tuning methods? Let's see what Feiteng technology experts say about dragon lizard technology
随机推荐
RPC remote procedure call
鲁迅:我不记得说没说过,要不你自己查!
【已解决】新版Pycharm(2022)连接服务器进行上传文件报错“Command rsync is not found in PATH”,无法同步文件
服务器网络测试的方法
Five day travels to Beijing
HU相关配置
这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
A quick overview of transformer quantitative papers in emnlp 2020
Showdoc vulnerability learning - cnvd-2020-26585 (arbitrary file upload)
Sword finger offer 58 - I. flip word order
代码接口自动化的有点
C#委托的使用案例
Redison 3.17.5 release, officially recommended redis client
软件调优方法有哪些?看看飞腾技术专家怎么说 | 龙蜥技术
二零二零年终总结
Primary key in MySQL secondary index - MySQL has a large number of same data paging query optimization
Do me a favor ~ don't pay attention, don't log in, a questionnaire in less than a minute
The code interface is a little automated
Gossip: it's really important to have a rod in your hand and a net on your shoulder. As for how many fish are in the basket?
Shell Scripts相关