0
点赞
收藏
分享

微信扫一扫

Nginx架构篇(4)php开发

RIOChing 2022-06-08 阅读 68

自学站点:​​http://www.w3school.com.cn/php/index.asp​​


示范案例

​​http://www.w3school.com.cn/php/php_mysql_insert.asp​​

  • UI:构图
  • 前端:通过表单,文本框,提交按钮,页面布局
  • 后端:php连接函数
  • 后端:php插入函数
  • DBA:实现后台数据库的写入。
  • OP:业务上线


准备前台html页面

vim 1.html 

<html>
<body>
<img src="logo.jpg" />

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>
  • html 页面的开始
  • body页面内容的开始
  • form 表单,整理input
  • input,文本框
  • /form 表单结束
  • /body 页面内容结束
  • /html 页面结束

Nginx架构篇(4)php开发_nginx


准备php中间件

vim insert.php 

<?php
$con = mysql_connect("192.168.19.100","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>
  • mysql_connect()连接数据库函数
  • mysql_select_db()选择数据库函数
  • $sql 插入数据变量
  • INSERT INTO mysql的插入语言。


准备表和库

create database my_db;
use my_db;
create table Persons (FirstName varchar(50), LastName varchar(50),Age int );
grant all on *.* to root@'%' identified by '123456';
grant all on *.* to root@'192.168.19.100' identified by '123456';


后台数据输出页面

vim /usr/share/nginx/html/select.php

<?php
$con = mysql_connect("localhost","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>


测试用户输入页面

Nginx架构篇(4)php开发_nginx_02

Nginx架构篇(4)php开发_linux_03


测试数据输出页面

Nginx架构篇(4)php开发_linux_04

举报

相关推荐

0 条评论