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

 

相关文章:

  • 2021-07-08
  • 2021-07-16
  • 2021-12-03
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2021-07-27
  • 2022-02-08
  • 2021-12-03
  • 2022-02-27
相关资源
相似解决方案