北京app建设 网站开发公司,wordpress不能更新插件,网站网站怎么搭建,设计师灵感网站前几天做到一些CMS的题#xff0c;涉及一些sql的代码审计#xff0c;于是尝试着自己开发一个连接数据库的博客#xff0c;加深一遍理解
简单实现了登录#xff0c;验证#xff0c;登出#xff0c;目录#xff0c;增删改查等功能
下面贴代码
conn.php
?phpsessi…前几天做到一些CMS的题涉及一些sql的代码审计于是尝试着自己开发一个连接数据库的博客加深一遍理解
简单实现了登录验证登出目录增删改查等功能
下面贴代码
conn.php
?phpsession_start();$username root;
$password root;$port 3306;
$host localhost;
$db blog;$conn new mysqli($host,$username,$password,$db,$port);if($conn-connect_error){die(数据库连接失败.$conn-connect_error);
}check.php
?phpif($_SESSION[login]!1){header(location:login.html);
}index.php
?phpheader(location:main.php);? index.html
!DOCTYPE html
htmlheadtitle博客系统登陆/titlemeta charsetutf-8/headbodycenterbrh1博客系统管理员登陆/h1hrform actionlogin.php enctypeapplication/x-www-form-urlencoded methodpost账号input typetext nameusername br br密码input typepassword namepassword br brinput typesubmit value登陆/form/center/body
/html login.php
?phprequire conn.php;$username $_POST[username];
$password $_POST[password];$sql select * from user where username $username and password $password;$result $conn-query($sql);if(!$result){die(查询失败);
}if($row$result-fetch_array()){$_SESSION[login]1;echo 登陆成功欢迎你.$row[username];
}else{echo 登陆失败;
}$conn-close();?!DOCTYPE html
htmlheadtitle博客首页/titlemeta charsetutf-8/headbodycenterbrh1博客首页/h1hra hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/a/center/body
/html logout.php
?phpsession_start();$_SESSION[login]0;session_destroy();header(location:main.php); main.php
!DOCTYPE html
htmlheadtitle博客首页/titlemeta charsetutf-8/headbodycenterbrh1博客首页/h1hra hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/a/center/body
/html page_add.php
?phprequire conn.php;
require check.php;$title$_POST[title];
$content$_POST[content];if(isset($title) isset($content)){$sql insert into page (title,content) values($title,$content);$result $conn-query($sql);if($result){echo 文章新增成功;}else{echo 文章新增失败.$conn-error;}
}?!DOCTYPE html
htmlheadtitle新增文章/titlemeta charsetutf-8/headbodycenterbrh1新增文章/h1a hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/aa hreflogout.php退出系统/ahrform actionpage_add.php enctypeapplication/x-www-form-urlencoded methodpost标题input typetext nametitle br br内容input typetext namecontent br brinput typesubmit value录入文章/form/center/body
/html page_delete.php
?phprequire conn.php;
require check.php;$id$_GET[id];if(isset($id) ){$sql delete from page where id $id;$result $conn-query($sql);if($result){echo 文章删除成功;}else{echo 文章删除失败.$conn-error;}
}$conn-close();?!DOCTYPE html
htmlheadtitle博客首页/titlemeta charsetutf-8/headbodycenterbrh1博客首页/h1hra hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/aa hreflogout.php退出系统/a/center/body
/html page_detail.php
?phprequire conn.php;$id $_GET[id];$id$id?$id:1;$sql select id,title,content from page where id $id;
echo $sql;$result $conn-query($sql);$page $result-fetch_array();?!DOCTYPE html
htmlheadtitle我的博客/titlemeta charsetutf-8/headbodycenterbrh1?$page[title];?/h1a hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/ahrp?$page[content];?/p/center/body
/html?php$conn-close();
? page_ edit.php
?phprequire conn.php;
require check.php;$title$_POST[title];
$content$_POST[content];
$id$_POST[id];if(isset($title) isset($content)){$sql update page set title $title,content $content where id $id;$result $conn-query($sql);if($result){echo 文章修改成功;}else{echo 文章修改失败.$conn-error;}
}else{$id $_GET[id];$id$id?$id:1;$sql select id,title,content from page where id $id;$result $conn-query($sql);$page $result-fetch_array();
}?!DOCTYPE html
htmlheadtitle修改文章/titlemeta charsetutf-8/headbodycenterbrh1修改文章/h1a hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/aa hreflogout.php退出系统/ahrform actionpage_edit.php enctypeapplication/x-www-form-urlencoded methodpostinput typehidden nameid value?$page[id];?标题input typetext nametitle value?$page[title];? br br内容input typetext namecontent value?$page[content];? br brinput typesubmit value录入文章/form/center/body
/html?php$conn-close();
? page_list.php
?phprequire conn.php;$sql select id,title from page;$result $conn-query($sql);$list $result-fetch_all(MYSQLI_ASSOC);?!DOCTYPE html
htmlheadtitle我的博客/titlemeta charsetutf-8/headbodycenterbrh1文章列表/h1a hrefmain.php首页/a|a hrefpage_list.php文章列表/a|a hrefpage_add.php新增文章/ahrul?phpforeach($list as $p){?lia hrefpage_detail.php?id?$p[id];??$p[title];?| a hrefpage_detail.php?id?$p[id];?查看a| a hrefpage_edit.php?id?$p[id];?修改a| a hrefpage_delete.php?id?$p[id];?删除a/li?php}?/ul/center/body
/html?php$conn-close();
? 总结
什么是sql
sql是一门语言通过sql语句可以快速实现数据的增删改查 Create 增 Delete 删 Update 改 Read 查 CURD 就是指对数据的增删改查 什么是数据库
关系型数据库
非关系型数据库 关系型数据库
把所有的数据变为表格存放
常见有
Oracle Mysql/MariaDB SQLServer Access Sqlite
非关系型数据库
nosql数据库
sns 社交软件 web2.0 所有内容 由用户产生 并 由用户消费
Membase MongoDB Mysql/Mariadb 为主 博客系统代码
sql语句
select id,username,password from user;
update page set titleaaa,contentbbb where id 1;
delete from page where id 1;
insert into page (title,content) values(aaa,bbb); php语句
$conn new mysqli($host,$username,$password,$db,$port);
$conn-query();
$result-fetch_all();
$result-fetch_array();