程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php mysql數據庫操作教程

php mysql數據庫操作教程

編輯:關於PHP編程

php mysql數據庫操作教程 本教程講了三個實例都是關於php操作mysql數據庫的教程,一是連接mysql數據庫,二是查詢數據庫字段名字,三是查詢數據庫記錄。

php教程 mysql教程數據庫教程操作教程
本教程講了三個實例都是關於php操作mysql數據庫的教程,一是連接mysql數據庫,二是查詢數據庫字段名字,三是查詢數據庫記錄。
*/
//連接mysql數據庫

$link = mysql_connect("localhost", "mysql_user", "mysql_password")
        or die("could not connect: " . mysql_error());
    print ("connected successfully");
    mysql_close($link);


 
//查詢mysql字段名

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

$fields = mysql_list_fields("database1", "table1", $link);
$columns = mysql_num_fields($fields);

for ($i = 0; $i < $columns; $i++) {
    echo mysql_field_name($fields, $i) . "n";
}

//查詢數據

$conn=mysql_connect("localhost","phpdb","phpdb")
        or die("不能連接數據庫服務器: ".mysql_error());
mysql_select_db("test",$conn) or die ("不能選擇數據庫: ".mysql_error()); 
$result = mysql_query("select * from user",$conn);
while($row=mysql_fetch_array($result)){ 
print "name:".$row[1]; 
print " address:".$row[3]; 
print " tel:".$row[4]; 
print " email:".$row[5];
echo

"<br>";
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved