摘要:<?php /** * Mysqli的使用 */ //連接數(shù)據(jù)庫(kù) $conn = mysqli_connect('127.0.0.1','root','31415926','phpcn','3306'); if(!$conn){ &nb
<?php /** * Mysqli的使用 */ //連接數(shù)據(jù)庫(kù) $conn = mysqli_connect('127.0.0.1','root','31415926','phpcn','3306'); if(!$conn){ exit('數(shù)據(jù)庫(kù)連接失?。?#39;.mysqli_connect_error()); } //查詢數(shù)據(jù) //$sql = "SELECT `name`,`phone` FROM `user` WHERE `uid`=5;"; //$sql = "SELECT `uid`,`name`,`phone` FROM `user` WHERE `country`='日本' ORDER BY `uid` DESC LIMIT 5;"; /*$sql = "SELECT COUNT(*) AS num FROM `user`;"; $result = mysqli_query($conn,$sql); $array=[]; while($res = mysqli_fetch_assoc($result)){ $array[]=$res; } echo '<pre>';*/ //print_r($array); //添加數(shù)據(jù) /*$sql="INSERT INTO `director`(`name`,`phone`,`country`,`add_time`) VALUES ('宮崎駿','12345678912', '日本','1546572786');"; $result = mysqli_query($conn,$sql); print_r($result); echo '<hr>'; //更新數(shù)據(jù) $sql = "UPDATE `director` SET `name`='李安',`country`='中國(guó)' WHERE `tid`=1;"; $result = mysqli_query($conn,$sql); print_r($result);*/ //刪除數(shù)據(jù) $sql = "DELETE FROM `director` WHERE `tid`=7;"; $result = mysqli_query($conn,$sql); print_r($result); //釋放內(nèi)存 mysqli_free_result($result); //關(guān)閉連接 mysqli_close($conn);
總結(jié):通過這這章的學(xué)習(xí),認(rèn)識(shí)了MYSQL以及操作軟件的使用,并且學(xué)會(huì)了使用php中的mysqli函數(shù)對(duì) 數(shù)據(jù)庫(kù)進(jìn)行增刪改查操作,同時(shí)學(xué)到了函數(shù)封裝的思想,函數(shù)封裝使的數(shù)據(jù)庫(kù)操作更加方便和安全, 與pdo操作相比較,雖然mysqli簡(jiǎn)單,但是pdo的預(yù)處理更加的安全。
批改老師:韋小寶批改時(shí)間:2019-01-04 13:06:23
老師總結(jié):寫的很不錯(cuò)!總結(jié)的也很不錯(cuò)!課后要記得多練習(xí)!