数据访问

2018-06-17 23:25:56来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>


<table width="100%" border="1" cellpadding="0" cellspacing="0">

<tr>
<td>代号</td>
<td>姓名</td>
<td>性别</td>
<td>民族</td>
<td>生日</td>
</tr>

<?php

//造一个mysqli对象,造连接对象
$db = new MySQLi("localhost","root","123","mydb");

//准备一条SQL语句
$sql = "select * from info";

//执行SQL语句,如果是查询语句,成功返回结果集对象
$reslut = $db->query($sql);

//判断返回是否执行成功
if($reslut)
{
while($attr = $reslut->fetch_row())
{
echo "<tr>
<td>{$attr[0]}</td>
<td>{$attr[1]}</td>
<td>{$attr[2]}</td>
<td>{$attr[3]}</td>
<td>{$attr[4]}</td>
</tr>";
}

}



?>

</table>






</body>
</html>







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>

<?php

//造连接对象
$db = new MySQLi("localhost","root","123","mydb");

//准备SQL语句
$sql = "delete from info where code='p004'";

//执行SQL语句
$r = $db->query($sql);

if($r)
{
echo "执行成功";
}
else
{
echo "执行失败";
}


?>

</body>
</html>







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>



<?php
$db = new MySQLi("localhost","root","123","mydb");
$sql = "select * from nation";
$result = $db->query($sql);

echo "<select>";

if($result)
{
while($attr = $result->fetch_row())
{
echo "<option value='{$attr[0]}'>{$attr[1]}</option>";
}
}

echo "</select>";

?>





</body>
</html>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:如何利用docker快速构建MySQL主从复制环境

下一篇:mysql 5.7以上版本下载及安装