<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2015/6/26
* Time: 19:10
*/
$conn=@mysql_connect('localhost','root','');
if($conn){
// echo '连接成功';
mysql_select_db('myapp',$conn);
$res=mysql_query("SELECT *FROM users");
$count=mysql_num_rows($res);
for($i=0;$i<$count;$i++){
$res_arr=mysql_fetch_assoc($res);
print_r($res_arr);
}
}else {
echo '连接失败';
}
?>
</body>
</html>
$conn=@mysql_connect(‘localhost’,’root’,”);首先创建服务器连接,用户名是root密码暂时为空,并复制给conn
mysql_select_db(‘myapp’,$conn);如果conn为真,连接成功,并选择数据库myapp
$res=mysql_query(“SELECT *FROM users”);在users表中查找结果
count=mysqlnumrows( res); 讲查找结果条数赋值给count变量
for(
i=0;
i<
count;
i++){
resarr=mysqlfetchassoc(
res);
print_r($res_arr);
}
循环输出得到的数组