青鸟的天空

积分与排名

最新评论

PHP连接Mysql的实例

PHP连接Mysql的实例


<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>

posted on 2007-10-16 09:08 断桥诗轩 阅读(10468) 评论(2)  编辑 收藏 引用 所属分类: WEB编程数据库编程PHP

评论

# re: PHP连接Mysql的实例 2011-01-04 22:40 ddd

ddddddddddd  回复  更多评论   

# re: PHP连接Mysql的实例 2013-12-31 10:02 chinapubmed

非常不错,成功了。谢谢!  回复  更多评论   

只有注册用户登录后才能发表评论。