PHP連接數(shù)據(jù)庫(kù)實(shí)現(xiàn)頁(yè)面增刪改查效果
效果圖
實(shí)現(xiàn)代碼
sql
-- phpMyAdmin SQL Dump -- version 4.5.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: 2022-03-15 17:51:32 -- 服務(wù)器版本: 10.1.13-MariaDB -- PHP Version: 5.6.21 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `a` -- -- -------------------------------------------------------- -- -- 表的結(jié)構(gòu) `search` -- CREATE TABLE `search` ( `id` int(11) NOT NULL, `content` text COLLATE utf8_vietnamese_ci NOT NULL COMMENT '內(nèi)容' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci; -- -- 轉(zhuǎn)存表中的數(shù)據(jù) `search` -- INSERT INTO `search` (`id`, `content`) VALUES (21, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'), (22, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'), (23, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'), (24, '陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴陳作業(yè)貴'), (25, '陳作業(yè)貴'), (26, '陳作業(yè)貴'), (27, '陳作業(yè)貴'), (28, '陳作業(yè)貴'), (29, '000000'), (30, ''); -- -- Indexes for dumped tables -- -- -- Indexes for table `search` -- ALTER TABLE `search` ADD PRIMARY KEY (`id`); -- -- 在導(dǎo)出的表使用AUTO_INCREMENT -- -- -- 使用表AUTO_INCREMENT `search` -- ALTER TABLE `search` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=67; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
cyg.php
<?php $link=mysqli_connect('localhost','root','','a'); //然后是指定php鏈接數(shù)據(jù)庫(kù)的字符集 mysqli_set_charset($link,'utf8'); $sql="select * from search"; //模糊查詢(xún)出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦 $result=mysqli_query($link,$sql);//運(yùn)行sql ?> <!--顯示的效果--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <table border="1" cellpadding="5"> <tr> <td>id</td> <td>標(biāo)題</td> <td>內(nèi)容</td> <?php while ($row=mysqli_fetch_array($result)) {//把對(duì)象編程數(shù)組輸出,不然會(huì)報(bào)錯(cuò)哦 # code... ?> <tr> <td><?=$row['id'];?></td> <td><?=$row['content'];?></td> <td><a href="update.php?id=<?php echo $row['id']; ?>" rel="external nofollow" >更新</a></td> <td><a href="delete.php?id=<?php echo $row['id']; ?>" rel="external nofollow" >刪除</a></td> <td><a href="create.php" rel="external nofollow" rel="external nofollow" rel="external nofollow" >創(chuàng)建</a></td> </tr> <?php } ?> </tr> </table> </body> </html>
delete.php
<?php $link=mysqli_connect('localhost','root','','a'); //然后是指定php鏈接數(shù)據(jù)庫(kù)的字符集 mysqli_set_charset($link,'utf8'); //$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'"; //模糊查詢(xún)出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦 $result=mysqli_query($link,"DELETE FROM search WHERE id ='$_GET[id]'");//運(yùn)行sql $sql="select * from search"; //模糊查詢(xún)出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦 $result=mysqli_query($link,$sql);//運(yùn)行sql ?> <!--顯示的效果--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <table border="1" cellpadding="5"> <tr> <td>id</td> <td>標(biāo)題</td> <td>內(nèi)容</td> <?php while ($row=mysqli_fetch_array($result)) {//把對(duì)象編程數(shù)組輸出,不然會(huì)報(bào)錯(cuò)哦 # code... ?> <tr> <td><?=$row['id'];?></td> <td><?=$row['content'];?></td> <td><a href="update.php?id=<?= $row['id']; ?>" rel="external nofollow" rel="external nofollow" >更新</a></td> <td><a href="delete.php?id=<?= $row['id']; ?>" rel="external nofollow" rel="external nofollow" >刪除</a></td> <td><a href="create.php" rel="external nofollow" rel="external nofollow" rel="external nofollow" >創(chuàng)建</a></td> </tr> <?php } ?> </tr> </table> </body> </html>
update.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="update.php" method="GET"> <input type="hidden" name="id" value="<?php echo $_GET['id']?>"> <input type="text" name="content"> <input type="submit" value="搜索"> </form> </body> </html> <?php $link=mysqli_connect('localhost','root','','a'); //然后是指定php鏈接數(shù)據(jù)庫(kù)的字符集 mysqli_set_charset($link,'utf8'); //$sql = "DELETE FROM `search` WHERE `id` = '$_POST[id]'"; //模糊查詢(xún)出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦 $result=mysqli_query($link,"UPDATE search set content='$_GET[content]' WHERE id ='$_GET[id]'");//運(yùn)行sql $sql="select * from search"; //模糊查詢(xún)出像數(shù)據(jù)庫(kù)中的title或者content里面的值或者說(shuō)像數(shù)據(jù)庫(kù)中的title或者content里面的某一段值相對(duì)應(yīng)的就行了,就可以輸出啦 $result=mysqli_query($link,$sql);//運(yùn)行sql ?> <!--顯示的效果--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <table border="1" cellpadding="5"> <tr> <td>id</td> <td>標(biāo)題</td> <td>內(nèi)容</td> <?php while ($row=mysqli_fetch_array($result)) {//把對(duì)象編程數(shù)組輸出,不然會(huì)報(bào)錯(cuò)哦 # code... ?> <tr> <td><?=$row['id'];?></td> <td><?=$row['content'];?></td> <td><a href="update.php?id=<?= $row['id']; ?>" rel="external nofollow" rel="external nofollow" >更新</a></td> <td><a href="delete.php?id=<?= $row['id']; ?>" rel="external nofollow" rel="external nofollow" >刪除</a></td> <td><a href="create.php" rel="external nofollow" rel="external nofollow" rel="external nofollow" >創(chuàng)建</a></td> </tr> <?php } ?> </tr> </table> </body> </html>
create.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="create.php" method="POST"> <input type="text" name="content"> <input type="submit" value="提交"> </form> </body> </html> <?php if(!$_POST['content']) { exit(); } $content=$_POST['content']; $link=mysqli_connect('localhost','root','','a'); //然后是指定php鏈接數(shù)據(jù)庫(kù)的字符集 mysqli_set_charset($link,'utf8'); $sql = "INSERT INTO search(content) VALUES ('{$content}')"; $result=mysqli_query($link,$sql); echo "<script>alert('創(chuàng)建成功');</script>"; ?>
以上就是PHP連接數(shù)據(jù)庫(kù)實(shí)現(xiàn)頁(yè)面增刪改查效果的詳細(xì)內(nèi)容,更多關(guān)于PHP增刪改查的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Vue項(xiàng)目通過(guò)node連接MySQL數(shù)據(jù)庫(kù)并實(shí)現(xiàn)增刪改查操作的過(guò)程詳解
- ASP.NET?Core使用EF?SQLite對(duì)數(shù)據(jù)庫(kù)增刪改查
- JDBC實(shí)現(xiàn)數(shù)據(jù)庫(kù)增刪改查功能
- 搭建MyBatis-Plus框架并進(jìn)行數(shù)據(jù)庫(kù)增刪改查功能
- 詳解Java數(shù)據(jù)庫(kù)連接JDBC基礎(chǔ)知識(shí)(操作數(shù)據(jù)庫(kù):增刪改查)
- 使用IDEA對(duì)Oracle數(shù)據(jù)庫(kù)進(jìn)行簡(jiǎn)單增刪改查操作
- MySQL表的增刪改查(CRUD)
相關(guān)文章
php實(shí)現(xiàn)用于刪除整個(gè)目錄的遞歸函數(shù)
這篇文章主要介紹了php實(shí)現(xiàn)用于刪除整個(gè)目錄的遞歸函數(shù),涉及php遞歸算法與目錄操作技巧,需要的朋友可以參考下2015-03-03PHP實(shí)現(xiàn)SQL語(yǔ)句格式化功能的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)SQL語(yǔ)句格式化功能的方法,基于github上開(kāi)源代碼實(shí)現(xiàn)的SQL語(yǔ)句格式化功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2017-07-07PHP學(xué)習(xí)筆記(三):數(shù)據(jù)類(lèi)型轉(zhuǎn)換與常量介紹
這篇文章主要介紹了PHP學(xué)習(xí)筆記(三):數(shù)據(jù)類(lèi)型轉(zhuǎn)換與常量介紹,本文講解了PHP數(shù)據(jù)類(lèi)型相互轉(zhuǎn)換、常量的聲明與使用等內(nèi)容,需要的朋友可以參考下2015-04-04php中$_GET與$_POST過(guò)濾sql注入的方法
這篇文章主要介紹了php中$_GET與$_POST過(guò)濾sql注入的方法,包含了addslashes_deep函數(shù)與數(shù)組的操作方法,是非常具有實(shí)用價(jià)值的技巧,需要的朋友可以參考下2014-11-11php 下載保存文件保存到本地的兩種實(shí)現(xiàn)方法
以下是對(duì)php下載保存文件保存到本地的兩種實(shí)現(xiàn)方法進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下2013-08-08php實(shí)現(xiàn)xml轉(zhuǎn)換數(shù)組的方法示例
這篇文章主要介紹了php實(shí)現(xiàn)xml轉(zhuǎn)換數(shù)組的方法,結(jié)合具體實(shí)例形式分析了php操作xml格式文件實(shí)現(xiàn)轉(zhuǎn)換數(shù)組的相關(guān)操作技巧,涉及xml格式數(shù)據(jù)的載入、遍歷、轉(zhuǎn)換等方法,需要的朋友可以參考下2017-02-02WordPress開(kāi)發(fā)中自定義菜單的相關(guān)PHP函數(shù)使用簡(jiǎn)介
這篇文章主要介紹了WordPress開(kāi)發(fā)中自定義菜單的相關(guān)PHP函數(shù)使用,包括過(guò)濾掉自定義菜單中無(wú)用的class值的方法,需要的朋友可以參考下2016-01-01