MYSQL操作

//連接////////////////////////////////////////////////////////////////
$link = mysql_connect("mysql_host", "mysql_login", "mysql_password")
  or die ("Could not connect to MySQL");
 
mysql_select_db ("my_database")
  or die ("Could not select database");
 
//查詢/////////////////////////////////////////////////////////////
  $query = "SELECT * FROM my_table";
  $result = mysql_query ($query)
    or die ("Query failed");
 
  // printing HTML result
//打印///////////////////////////////////////////////////////////////
  print "<table>/n";
  while ($line = mysql_fetch_row($result)) {
    print "/t<tr>/n";
    while(list($col_name, $col_value) = each($line)) {
      print "/t/t<td>$col_value</td>/n";
    }
    print "/t</tr>/n";
  }
  print "</table>/n";
 
 
//關閉連接///////////////////////////////////////////////////////
  mysql_close($link);
 
 
 
函數
mysql_num_rows 返回結果集的行數
 
發佈了46 篇原創文章 · 獲贊 8 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章