PHP 連線資料庫

2022-07-20 10:15:10 字數 509 閱讀 1048

php7已經不用mysql_connect來建立資料庫了。而是改用mysql_connect來建立資料庫。

這裡只介紹一種建立資料庫的方法:

連線資料庫的方式:

$mysqli = new mysqli('localhost', 'root', '1111', 'lib');

查詢mysql語句:

$res = $mysqli->query('select * from tb_student');

mysql_assoc: 從結果集中取得一行作為關聯陣列

mysql_array:  從結果集中取得一行作為關聯陣列,或數字陣列,或二者兼有

mysql_row:    從結果集中取得一行作為數字陣列

一、可以一行一行讀取:

print_r(mysqli_fetch_assoc($res));

二、可以一起讀出來,然後有迴圈顯示:  

$n = 0;

while($n < mysqli_num_rows($res))

php連線資料庫

create table message id tinyint 1 not null auto increment,user varchar 25 not null,title varchar 50 not null,content tinytext not null,lastdate date n...

php連線資料庫

天貓內部優惠券 設定資料庫變數 db host localhost 資料庫主機名稱,一般都為localhost db user root 資料庫使用者帳號,根據個人情況而定 db passw 資料庫使用者密碼,根據個人情況而定 db name test 資料庫具體名稱,以剛才建立的資料庫為準 連線資...

PHP連線資料庫

php連線資料庫函式 mysql connect 開啟mysql連線 mysql select db 開啟乙個資料庫 和or die 隱藏錯誤和條件顯示 mysql connect 主機 使用者名稱 密碼 mysql select db 開啟資料庫 鏈結標示符 如果不是特宣告連線標示符,則預設為是上...