2011-03-03 50 views
3

對不起這個問題,但我從來沒有使用SQLite的工作,和我通過SQLite的網站了,下載了「預編譯的二進制對於Windows」文件試圖使它們可用於我的目的,但我couldnot,我看到與數據庫,表的工作教程。如何導入SQLite的DB3文件

我的任務是從SQLite獲取數據並將它們放到magento mysql數據庫中。所以爲此,我將SQLite數據庫轉儲文件作爲.db3文件,具有db轉儲文件(20110125_SIZE)大小的txt文件。

那麼我怎樣才能將它導入到SQLite中。請如果任何人與SQLite3合作,幫助我瞭解.db3文件,我怎麼能看到他們的記錄。

我有sqlite3的數據庫轉儲作爲dbname.db3,

於是我想這sqllite從PHP連接。這是我從論壇獲得的示例代碼。

$db = openDatabase(); 
    unset($db); 

    function openDatabase() { 
     $dbFile = realpath('dbname.db3'); 
     echo $dbFile . "\n"; 
     $needDbCreate = !file_exists($dbFile); 
     $db = new SQLiteDatabase($dbFile) or die((file_exists($dbFile)) ? "Unable to open" : "Unable to create"); 
     if($needDbCreate) { 

     } 
     return $db; 
    } 

但我越來越致命的例外。

Fatal error: Uncaught exception 'SQLiteException' with message 'SQLiteDatabase::_construct() [sqlitedatabase.--construct]: file is encrypted or is not a database' in C:\wamp\www\SQLITE\index.php:23 Stack trace: #0 C:\wamp\www\SQLITE\index.php(23): SQLiteDatabase->_construct('C:\wamp\www\SQL...') 1 C:\wamp\www\SQLITE\index.php(15): openDatabase() #2 {main} thrown in C:\wamp\www\SQLITE\index.php on line 23

但是,當我嘗試與PDO相同的sqldump,我已連接。

try {  
     $dbh = new PDO("sqlite:C:\wamp\www\SQLITE\dbname.db3"); 
     echo 'Db Connected <br/>'; 

    } 
    catch(PDOException $e) 
    { 
     echo $e->getMessage(); 
    } 

這裏我不知道這個轉儲中可用的表的列表,所以我如何查詢他們列表,然後從他們獲取記錄。

請幫我解決這個問題ti連接並從php瀏覽表格。

Sorry for posting here in answer section, i wanted to highlight the code.

感謝

+1

編輯我的答覆覆蓋應該已被編輯成你原來的問題:) – 0xC0000022L 2011-03-03 02:02:43

回答

3

在安裝SQLite的一個系統,你通常也有sqlite3命令行程序。它既可以在命令行中使用,也可以在交互模式下使用,以便轉儲數據或將其加載到(二進制)數據庫文件中。

sqlite3 ./database.file 

這會給你的交互提示,在那裏你可以發出SQL命令或如.help.dump特殊命令。

也有更多的圖形工具,但它們可能是你想做的事情的矯枉過正。

編輯:看到你(目前在答題部分)的答覆,看來你.db3文件根本不是二進制格式SQLite3的,而是也許轉儲。這將是一個問題。如果它是轉儲文件,你必須首先將它加載到合適的數據庫文件中。

cat yourdump.sql|sqlite3 ./realdb.db3 
+0

您好,感謝這個問題的一部分,我得到它的工作通過使用PDO連接。 – Elamurugan 2011-03-03 02:51:25

+1

@Ela:好的,所以這個文件是一個真正的二進制格式的SQLite3數據庫? – 0xC0000022L 2011-03-03 02:55:40

0
call three times 
$rr=exec("sqlite3 database.db \".separator '|'\" "); 
$rr=exec("sqlite3 database.db \".import myfile.txt tablename\" "); 
$rr= exec ("sqlite3 database.db \"pragma encoding = 'utf-8'\" "); 

or 
single line 
$rr=exec("sqlite3 database.db \".separator '|'\" && sqlite3 database.db \"pragma encoding = 'utf-8'\" && sqlite3 database.db \".import myfile.txt tablename\" ");