(PHP 7 >= 7.4.0, PHP 8)
SQLite3::backup — 將一個資料庫備份到另一個資料庫
$destination
, string $sourceDatabase
= "main", string $destinationDatabase
= "main"): boolSQLite3::backup() 會將一個資料庫的內容複製到另一個資料庫,並覆蓋目標資料庫的內容。它可用於建立資料庫的備份,或將記憶體中的資料庫複製到永久檔案或從永久檔案複製到記憶體中。
從 SQLite 3.27.0 (2019-02-07) 開始,也可以使用 VACUUM INTO 'file.db';
語句將資料庫備份到新檔案。
destination
使用 SQLite3::open() 開啟的資料庫連線。
sourceDatabase
資料庫名稱。主資料庫為 "main"
,臨時資料庫為 "temp"
,附加資料庫則是在 ATTACH
語句中 AS
關鍵字後指定的的名稱。
destinationDatabase
類似於 sourceDatabase
,但是用於 destination
。
範例 #1 備份現有資料庫
<?php
// $conn 是已開啟 sqlite3 資料庫的連線
$backup = new SQLite3('backup.sqlite');
$conn->backup($backup);
?>