PHP连接Mysql的实例
2009-07-07 09:08
561 查看
<html>
<head>
<title>connect.php</title>
</head>
<body>
/*PHP手册中的PHP连接Mysql的实例*/
<?php
/* 连接选择数据库 */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password") or die("Could not connect");
print "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");
/* 执行 SQL 查询 */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed");
/* 在 HTML 中打印结果 */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "\t<tr>\n";
foreach ($line as $col_value)
{
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
/* 释放资源 */
mysql_free_result($result);
/* 断开连接 */
mysql_close($link);
?>
</body>
<head>
<title>connect.php</title>
</head>
<body>
/*PHP手册中的PHP连接Mysql的实例*/
<?php
/* 连接选择数据库 */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password") or die("Could not connect");
print "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");
/* 执行 SQL 查询 */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed");
/* 在 HTML 中打印结果 */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "\t<tr>\n";
foreach ($line as $col_value)
{
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
/* 释放资源 */
mysql_free_result($result);
/* 断开连接 */
mysql_close($link);
?>
</body>
相关文章推荐
- php mysql操作mysql_connect连接数据库实例详解
- PHP连接MySQL实例实现增、删、改。
- php连接mysql实例
- javascript连接mysql与php通过odbc连接任意数据库的实例
- PHP 连接mysql 实例代码
- PHP 连接并操作MySQL的一个实例
- php连接mysql常规实例
- php mysql连接数据库实例
- php之连接到MySQL,并将数据储存在MySQL中的实例
- php 连接mysql实例代码
- PHP连接MYSQL实例一
- php yii连接mysql配置扩展
- php连接mysql
- WindowsServer2003 + IIS6.0 + ASP + NET + PHP + PERL + MSSQL + MYSQL 最新服务器安全设置技术实例
- PHP中MongoDB数据库的连接、添加、修改、查询、删除等操作实例
- JDBC 连接数据库实例(Oracle\SQLServer\MySQL 驱动下载)
- go连接mysql,redis并完成日志字符处理实例
- PHP调用MYSQL存储过程实例
- PHP MySQL 连接数据库,进行增、删、改、查、操作
- PHP与MySQL连接