後端教學-MYSQL 講師:邱小楓(邱珈蓉) 资料下载:www.1ppt.com/ziliao/ PPT课件下载:www.1ppt.com/kejian/ 范文下载:www.1ppt.com/fanwen/ 试卷下载:www.1ppt.com/shiti/ Word教程: www.1ppt.com/word/ Excel教程:www.1ppt.com/excel/ 优秀PPT下载:www.1ppt.com/xiazai/ PPT教程: www.1ppt.com/powerpoint/ 节日PPT模板:www.1ppt.com/jieri/ PPT素材下载:www.1ppt.com/sucai/ PPT背景图片:www.1ppt.com/beijing/ PPT图表下载:www.1ppt.com/tubiao/ PPT模板下载:www.1ppt.com/moban/ 行业PPT模板:www.1ppt.com/hangye/ 教案下载:www.1ppt.com/jiaoan/ 後端教學-MYSQL 講師:邱小楓(邱珈蓉)
常見的SQL指令 Select - 查詢 Insert - 插入 Update - 更新 Delete - 刪除
連接資料庫 <?php $link =mysqli_connect('localhost','root','password'); mysqli_query($link,"SET NAMES utf8"); if (!$link) { die(' 連線失敗,輸出錯誤訊息 : ' . mysql_error()); } echo ' 連線成功 '; ?>
妥善使用include
查詢資料 $sql=“select * from xxx”; $result = mysqli_query($link,$sql); while($row=mysqli_fetch_array($result)) { echo $row[0] ; echo $row[1] ; echo $row[2] ; }
新增資料 $sql=“select * from xxx”; $result = mysqli_query($link,$sql); $sql = "INSERT INTO `classtest`.`menu` (`id`, `name`, `price`, `description`, `type`, `ca`) VALUES (NULL, '".$fname."', '".$fp."', '".$des."', '".$pic."', '".$ca."');"; echo $sql."<br>"; $result = mysqli_query($conn,$sql);
修改資料 $sql=“select * from xxx”; $result = mysqli_query($link,$sql); $sql ="UPDATE `menu` SET `name` = '".$name."', `price` = '".$price."',`ca` = '".$ca."', `description` = '".$descrip."',`type` = '".$pic."' WHERE `menu`.`id` = ".$fid.";"; echo $sql."<br>"; $result = mysqli_query($conn,$sql); //回傳true 跟flase
刪除資料 $sql=“select * from xxx”; $result = mysqli_query($link,$sql); $sql = " DELETE FROM `menu` WHERE `id` = ".$fid.""; $result = mysqli_query($conn,$sql);