PHP连接MySQL
2010-09-29 08:25
169 查看
<!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>temp</title>
</head>
<body>
<?php
//连接数据库的参数
$host = "localhost";
$user = "root";
$pass = "zq19890319";
$db = "flower";
//创建一个mysql连接
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect");
//选择一个数据库
mysql_select_db($db) or die("Unable to select database!");
//开始查询
$query = "select *from login";
//执行SQL语句
$result = mysql_query($query) or die("Error in query:$query.".mysql_error());
//显示返回的记录集行数
if(mysql_num_rows($result)>0){
echo "<table cellpadding=10 border=1>";
while($row=mysql_fetch_row($result)){
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
}
echo "</table>";
}
else{
echo "记录未找到!";}
//释放记录集所占用的内存
mysql_free_result($result);
//关闭该数据库连接
mysql_close($connection);
?>
</body>
</html>
">
<html xmlns="http://www.w3.org/1999/xhtml
">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>temp</title>
</head>
<body>
<?php
//连接数据库的参数
$host = "localhost";
$user = "root";
$pass = "zq19890319";
$db = "flower";
//创建一个mysql连接
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect");
//选择一个数据库
mysql_select_db($db) or die("Unable to select database!");
//开始查询
$query = "select *from login";
//执行SQL语句
$result = mysql_query($query) or die("Error in query:$query.".mysql_error());
//显示返回的记录集行数
if(mysql_num_rows($result)>0){
echo "<table cellpadding=10 border=1>";
while($row=mysql_fetch_row($result)){
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
}
echo "</table>";
}
else{
echo "记录未找到!";}
//释放记录集所占用的内存
mysql_free_result($result);
//关闭该数据库连接
mysql_close($connection);
?>
</body>
</html>
相关文章推荐
- 中介PHP连接前台HTML与数据库MySQL
- php连接mysql 插入 更新 删除基本用法
- PHP连接Mysql,实现基本的增、删、改、查——用户管理系统
- php连接mysql的问题
- php_PHP与Mysql的连接
- php和mysql连接的个人总结
- php连接MySQL的两种方式对比
- php高版本不再使用mysql_connect()来连接数据库
- PHP使用数据库永久连接方式(mysql_pconnect)操作MySQL的是与非
- PHP 连接MAMP中 MySQL失败问题的解决
- PHP连接MySQL数据库的三种方式(mysql、mysqli、pdo)
- MySQL设置root密码后,PHP网页无法连接数据库。
- PHP新的连接MySQL方法mysqli
- (转)php连接mysql如何判断数据为空?
- MySQL与PHP连接
- PHP连接MySQL 及 MySQL基本函数
- PHP 5.5.0版以前的php+mysql的连接方法
- 如何putty安装php, apache, mysql(LAMP), 连接digital ocean server, 将自己的网站po上server
- php学习笔记(二)php与mysql连接与用php发送SQL查询