abstract:是在php5.0之后出現(xiàn)的對(duì)mysql數(shù)據(jù)庫(kù)進(jìn)行操作的函數(shù)庫(kù),mysqli對(duì)數(shù)據(jù)庫(kù)的操作主要是先連接,然后進(jìn)行增刪改查,最后關(guān)閉數(shù)據(jù)庫(kù)。$db = mysqli_connect('127.0.0.1','root','root','gzy1.14','3306');//連接數(shù)據(jù)庫(kù)的參數(shù)分別是主機(jī)ip地址,賬號(hào),密碼,數(shù)
是在php5.0之后出現(xiàn)的對(duì)mysql數(shù)據(jù)庫(kù)進(jìn)行操作的函數(shù)庫(kù),mysqli對(duì)數(shù)據(jù)庫(kù)的操作主要是先連接,然后進(jìn)行增刪改查,最后關(guān)閉數(shù)據(jù)庫(kù)。
$db = mysqli_connect('127.0.0.1','root','root','gzy1.14','3306');//連接數(shù)據(jù)庫(kù)的參數(shù)分別是主機(jī)ip地址,賬號(hào),密碼,數(shù)據(jù)庫(kù)名稱,還有默認(rèn)端口
$sql = "DELETE FROM `director` WHERE tid = 7;";/如同文件封裝一樣,數(shù)據(jù)庫(kù)操作也可以用方法進(jìn)行封裝,這樣方便以后的操作
$return = delete($db,$sql);
print_r($return);
mysqli_close($db);
function delete($db,$sql){//刪除方法
$return = mysqli_query($db,$sql);
return $return;
}
刪除,插入,更新的方法大同小異,而查詢方法相對(duì)而言更麻煩些:
$db = mysqli_connect('127.0.0.1','root','root','gzy1.14','3306');
$return = count_number($db,'user','country = "日本"');
print_r($return);
mysqli_close($db);
function count_number($db,$table,$where){
$sql = "SELECT COUNT(*) AS count_number FROM ".$table." WHERE ".$where;//COUNT(*)為mysqli內(nèi)置統(tǒng)計(jì)函數(shù),AS是將鍵改為count_number,要注意的是關(guān)鍵詞的兩邊要加空格。這里FROM后面和WHERE兩邊不加空格將會(huì)報(bào)錯(cuò)
$return = mysqli_query($db,$sql);
$return = mysqli_fetch_assoc($return);//獲取數(shù)組集
return $return['count_number'];//輸出數(shù)組$renturn的值
}
Correcting teacher:查無(wú)此人Correction time:2019-01-15 17:37:11
Teacher's summary:寫的還行??梢越M裝更好的增刪查改方法。比如條件分開,排序分開。 繼續(xù)加油。