2011-03-03 49 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\" ");