//1,鏈結資料庫
$con
=mysqli_connect
('localhost'
,'root'
,'root');
//var_dump($link);
//2,判斷是否鏈結成功if(
!$con
)//3,設定字符集
mysqli_set_charset
($con
,'utf8');
//4,選擇資料庫
mysqli_select_db
($con
,'test');
//5,準備sql語句 //select update insert delete
$sql
="select * from lol"
;//6,傳送sql語句
$res
=mysqli_query
($con
,$sql);
//var_dump($res);
//7,處理結果集
$result
=mysqli_fetch_assoc
($res);
$result
=mysqli_fetch_assoc
($res);
$result
=mysqli_fetch_assoc
($res);
var_dump
($result);
//8,關閉資料庫(釋放資源)
mysqli_close
($con
);
常用函式在處理結果集中使用:
1.一次輸出所有的結果
while
($rows
=mysqli_fetch_assoc
($res))
2,輸出乙個索引陣列
$result
=mysqli_fetch_row
($res);
var_dump
($result
);
3.輸出乙個既是索引又是關聯的陣列
$result
=mysqli_fetch_array
($res);
var_dump
($result
);
4,輸出查詢結果的總數
$result
=mysqli_num_rows
($res);
var_dump
($result
);
5,輸出修改,新增,刪除受影響的行數
$result
=mysqli_affected_rows
($res);
var_dump
($result
);
6,輸出你插入最後一行資料的id值
$res
=mysqli_insert_id
($link);
var_dump
($res
);
PHP和MYSQL資料庫的鏈結
在mysql資料庫的眾多函式中,用來連線的函式有兩個,分別是 mysql connect 和mysql pconnect 語法如下 int mysql connect string hostname port,string username string password int mysql pco...
PHP鏈結MYSQL資料庫
conn mysql connect 192.168.61.42 lepus 123456 result mysql db query lepus select from servers opaq conn 獲取查詢結果 row mysql fetch row result echo echo 顯示...
簡單的鏈結資料庫
hzblib.idal.isbiz sbiz hzblib.dal.factory.createsbiz hzblib.model.collectionslist sbiz.select select from s biz string strconn server 192.168.8.101 ui...