admin

一个php操作sqlite的相关代码
比较好用的sqlite管理软件 SQLiteStudio。可以创建sqlite,但是不知道为什么多个sql语句一起...
扫描右侧二维码阅读全文
13
2017/02

一个php操作sqlite的相关代码

比较好用的sqlite管理软件 SQLiteStudio。可以创建sqlite,但是不知道为什么多个sql语句一起执行的时候,有时候会有错误。<!--more-->

1、设置sqlite文件

$sqlitepath="sqlite-20170210-101.db";

2、插入记录

$db = NULL;$db=new PDO('sqlite:'.$sqlitepath);
$sql="INSERT INTO 'gustbook' ('card_id','order_id','title','content','admin_id','addtime') VALUES ( ".$card_id.",".$order_id.",'".$title."','".$content."','".$admin_id."',".time(). ")";
$result=$db->exec($sql);
$result=NULL;

3、删除记录<pre>
$db=NULL;$db=new PDO('sqlite:'.$sqlitepath);
$sql="DELETE FROM 'gustbook' where id = ".$id." and card_id=".$card_id;
$result=$db->exec($sql);
$result=NULL;
</pre>
4、修改记录<pre>
$db=NULL;$db=new PDO('sqlite:'.$sqlitepath);
$result=$db->exec("UPDATE gustbook SET re='$re',exptime='".time()."' where id =$id");
$result=NULL;
</pre>
5、查询单条记录<pre>
$db=new PDO('sqlite:'.$sqlitepath);
$result=$db->query("SELECT * FROM admin where username='".$username."' and passwd='".$passwd."'");
$row = $result->fetch();
if ($row){

$_SESSION['admin_id']=$row['id'];
$_SESSION['admin_username']=$row['username'];
msg('登陆成功','OK','<p>登陆成功</p><p>稍后进去管理后台</p>','admin.php?ac=list','进入后台面板','6');

}
else{

msg('登陆失败','提示','<p>请检查您的输入有错误</p><p>用户名密码错误</p>','admin.php?ac=login','重新登陆','6');

}
$result=NULL;
</pre>
6、查询多个记录,并循环<pre>
$db=NULL;$db=new PDO('sqlite:'.$sqlitepath);
$result=$db->query("SELECT * FROM 'gustbook' where card_id = ".$_SESSION['card_id']." order by id desc");
if ($result){
while($row = $result->fetch()){

echo $row['title'];

}
}
$result=NULL;
</pre>

Last modification:October 13th, 2018 at 10:11 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment

captcha
请输入验证码