Home > php教程 > PHP源码 > 数据库连接代码

数据库连接代码

PHP中文网
Release: 2016-05-25 17:11:43
Original
1583 people have browsed it

数据库连接代码

php中数据库连接代码

<?php 
//连接数据库
$link=mysql_connect("127.0.0.1","root","123456");
//选择数据库
mysql_select_db("userdb",$link);
//sql语句
$sql="select * from userInfo";
//设置查询出来的结果编码集也为utf8
mysql_query("set names utf8");
//执行sql语句
$rs=mysql_query($sql);
//返回受影响的行数
$num=mysql_num_rows($rs);
?>
<table border="1" align="center">
<tr>
<td>姓名</td>
<td>密码</td>
</tr>
<?php
//循环遍历
for($i=0;$i<mysql_num_rows($rs);$i++){
    //将结果集转化为数组
    $list=mysql_fetch_array($rs);
?>
<tr>
<td><?php echo $list["name"]?></td>
<td><?php  echo $list["pwd"]?></td>
</tr>
<?php
}
?>
Copy after login

   

以上就是数据库连接代码的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

               

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template