<p> Navicat For Mysql中新建数据库</p>
数据库中新建表
保存表
表中添加数据
打开ide,输入以下php代码,使用localhost打开该php文件
<?php
// ip地址、用户名、密码
$con=mysql_connect("localhost","root","123456");
// 判断是否连接成功
if(!$con){
die('数据库连接失败'.mysql_error());
}else{
// 设置编码格式
mysql_query("set name utf8");
// 选择数据库
mysql_select_db("test",$con);
// 选择数据表
$result=mysql_query("select * from user");
// 输出表格及th
echo "<table border='2' width='300'>
<tr>
<th>id</th><th>name</th>
<th>password</th>
</tr>";
// 遍历数据表中的内容
while($row=mysql_fetch_array($result)){
echo "<tr>";
// userid === 用户id 与数据表中的id名称对应
echo "<td>".$row['userid']."</td>";
// username === 用户名称 与数据表中的username名称对应
echo "<td>".$row['username']."</td>";
// password === 用户密码 与数据表中的密码对应
echo "<td>".$row['password']."</td>";
echo "</tr>";
}
echo "</table>";
}
// 关闭数据库
mysql_close($con);
?>
浏览器中显示的页面
个人博客?:点此进入(http://xueshuai.top)
PHP学习交流群?:PHP学习交流群
前端学习交流群?:前端交流群
微信公众号?:叮当Ding