php 配置sqlite

php 配置sqlite,第1张

PHP5已经绑定sqlite

1、手动添加的php的pdo的驱动扩展支持 ,在PHP.ini添加

extension=php_pdo.dll

extension=php_pdo_sqlite.dll

extension=php_sqlite.dll

extension_dir = "C:\Program Files\Apache Group\php5\ext"

2、在C:\Program Files\Apache Group\php5\ext保证有php_sqlite.dll,php_pdo_sqlite.dll,

php_pdo.dll扩展库

3、重启apache

4、下载SQLitemanager,create a database,保存名“db.sqlite”的数据库,建表,

或者sqliteadmin

5、在PHP链接SQLite

方法一、$db= new PDO('sqlite:db.sqlite') 

print_r($db)

$sth = $db->query("select * from aqo")

方法二、if ($db = sqlite_open('db.db', 0666, $sqliteerror)) { 

sqlite_query($db, 'CREATE TABLE foo (bar varchar(10))')

sqlite_query($db, "INSERT INTO foo VALUES ('fnord')")

$result = sqlite_query($db, 'select bar from foo')

var_dump(sqlite_fetch_array($result)) 

} else {

die($sqliteerror)

}

Sqlite数据库的加密

1、创建空的sqlite数据库。

//数据库名的后缀你可以直接指定,甚至没有后缀都可以

//方法一:创建一个空sqlite数据库,用IO的方式

FileStream fs = File.Create(“c:\\test.db“)

//方法二:用SQLiteConnection

SQLiteConnection.CreateFile(“c:\\test.db“)

创建的数据库是个0字节的文件。

2、创建加密的空sqlite数据库

//创建一个密码为password的空的sqlite数据库

SQLiteConnection.CreateFile(“c:\\test2.db“)                

SQLiteConnection cnn = new SQLiteConnection(“Data Source=c:\\test2.db“)

 SQLiteConnection cnn = new SQLiteConnection(“Data Source=D:\\test2.db“)

cnn.Open()

cnn.ChangePassword(“password“)

3、给未加密的数据库加密

SQLiteConnection cnn = new SQLiteConnection(“Data Source=c:\\test.db“)

cnn.Open()

cnn.ChangePassword(“password“)

4、打开加密sqlite数据库

//方法一

SQLiteConnection cnn = new SQLiteConnection(“Data Source=c:\\test2.db“)

cnn.SetPassword(“password“)

cnn.Open()

//方法二

SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder()

 builder.DataSource = @”c:\test.db“

builder.Password = @”password“

SQLiteConnection cnn = new SQLiteConnection(builder.ConnectionString)

cnn .Open()

分页

select * from messages limit 10,100

表示跳过10行,取100行的返回结果。

sqlite的事务特性,journal文件是事务开始产生的,直到整个事务结束才会消失,你在完成一个事务后,必须提交这次事务才能生效,比如PHP手册里的示例:

unlink('mysqlitedb.db')

$db = new SQLite3('mysqlitedb.db')

$stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id')

$stmt->bindValue(':id', 1, SQLITE3_INTEGER)

$result = $stmt->execute()

后边加个关闭连接的语句试试:$db->close()

如果还不行,就不太清楚了,试试升级下sqlite。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6788477.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存