本文目錄一覽:
- 1、如何讓php支持sqlite
- 2、如何在php中查詢sqlite 並進行展示
- 3、php創建sqlite資料庫後,增加內容會生成journal文件
- 4、PHP 操作 sqlite 時如何為 sqlite加密 和防止 用戶下載資料庫?
- 5、php 配置sqlite
- 6、PHP中如何使用sqlite
如何讓php支持sqlite
你好,php默認設置不支持,sqlite資料庫,如果你的是windows系統,那麼在php.ini找到extension=php_sqlite.dll這行,把前面的那個#號去掉,重啟nignx或者apache就行了。。。如果是linux系統。。就有點麻煩。。可能得編譯擴展模塊。。具體才複雜。。還跟支持庫有關,一般去網上找個教程。。對著做就沒啥問題。謝謝。
如何在php中查詢sqlite 並進行展示
// set access parameters
$db = “users.db”;
// open database file
// make sure script has read/write permissions!
$conn = sqlite_open($db) or die (“ERROR: Cannot open database”);
// create and execute INSERT query
$sql = “INSERT INTO users (id, username, country) VALUES (‘5’, ‘pierre’, ‘FR’)”;
sqlite_query($conn, $sql) or die(“Error in query execution: ” . sqlite_error_string(sqlite_last_error($conn)));
// create and execute SELECT query
$sql = “SELECT username, country FROM users”;
$result = sqlite_query($conn, $sql) or die(“Error in query execution: ” .sqlite_error_string(sqlite_last_error($conn)));
// check for returned rows
// print if available
if (sqlite_num_rows($result) 0) {
while($row = sqlite_fetch_array($result)) {
echo $row[0] . ” (” . $row[1] . “) “;
}
}
// close database file
sqlite_close($conn);
php創建sqlite資料庫後,增加內容會生成journal文件
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。
PHP 操作 sqlite 時如何為 sqlite加密 和防止 用戶下載資料庫?
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行的返回結果。
php 配置sqlite
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);
}
PHP中如何使用sqlite
PHP SQLite 的使用和配置方法:
在PHP 5.1.x 以後自帶了 SQLtie 資料庫功能,只需要在配置PHP.ini中開啟即可
;extension=php_sqlite.dll
在PHP 5.2.x 以後自帶了 SQLtie PDO資料庫功能,只需要在配置PHP.ini中開啟即可
;extension=php_pdo_sqlite.dll
SQLite 資料庫管理:
1、SQLiteManager與PHPmyadmin不同,需要添加管理的資料庫
2、Windows下使用添加路徑需要將 X: \**\** 改為 X:/**/**
3、 創建資料庫的時候需要指定SQLite 資料庫文件存放的路徑
原創文章,作者:HLFZ,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/131965.html