• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP数据库操作实例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

---恢复内容开始---

<?
   
/*本例是用PHP连接一个mysql数据库操作的演示,
实现连接打开一个库,并读取数据的基本功能。
数据库名称为:test    表名为:user
分别有7个字段:id userid sex age tel email address
服务器;数据库编码 均采用 utf-8
mysql_query("set names \'gbk\'"); // //这就是指定数据库字符集,一般放在连接数据库后(解决数据库乱码)
   
*/
?>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<style type="text/css">
<!--
input { font
-size:9pt;}
A
:link {text-decoration: underline; font-size:9pt;color:000059}
A
:visited {text-decoration: underline; font-size:9pt;color:000059}
A
:active {text-decoration: none; font-size:9pt}
A
:hover {text-decoration:underline;color:red}
body
,table {font-size: 9pt}
tr
,td{font-size:9pt}
-->
</style>
<title>注册会员列表 - 读取mysql的测试</title>
</HEAD>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<br><br><center><font color=green size=3><b>注 册 会 员 列 表</b></font></center>
<br>
<table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
   
<td width="5%" align="center" valign="bottom" height="19">ID</td>
   
<td width="10%" align="center" valign="bottom">姓名</td>
   
<td width="5%" align="center" valign="bottom">性别</td>
   
<td width="5%" align="center" valign="bottom">年龄</td>
   
<td width="20%" align="center" valign="bottom">联系电话</td>
   
<td width="20%" align="center" valign="bottom">电子邮件</td>
   
<td width="20%" align="center" valign="bottom">家庭住址</td>
</tr>
<?
   
//连接到本地mysql数据库
    $myconn=mysql_connect("localhost","root","root");
   
//选择test为操作库
    mysql_query("set names \'gbk\'"); // //这就是指定数据库字符集,一般放在连接数据库后面就系了
    mysql_select_db("test",$myconn);
   
$strSql="select * from user";
   
//用mysql_query函数从user表里读取数据
    $result=mysql_query($strSql,$myconn);
   
while($row=mysql_fetch_array($result))//通过循环读取数据内容
    {
?>
<tr>
   
<td align="center" height="19"><?echo$row["id"]?></td>
   
<td align="center"><?echo$row["userid"]?></td>
   
<td align="center"><?echo$row["sex"]?></td>
   
<td align="center"><?echo$row["age"]?></td>
   
<td align="center"><?echo$row["tel"]?></td>
   
<td align="center"><?echo$row["email"]?></td>
   
<td align="center"><?echo$row["address"]?></td>
</tr>
<?
    }
   
//关闭对数据库的连接
    mysql_close($myconn);
?>
</table>
</BODY>
</HTML>

http://www.cnblogs.com/xinlei/archive/2011/04/11/2012231.html

---恢复内容结束---


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP操作mysql数据库发布时间:2022-07-10
下一篇:
01.php与MySQL(基本操作)发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap