当前位置:首页 > 数据库 > SQlite

PHP-如何导入SQLite db3文件

对这个问题很抱歉,但是我从未使用过SQLite,而是浏览了SQLite网站,下载了“ Windows的预编译二进制文件”,这些文件试图使它们可用于我的用途,但我看不到有关数据库,表的实用教程.

我的任务是从SQLite获取数据并将其放入magento mysql DB中.因此,为此,我获得了SQLite DB转储文件作为.db3文件,txt文件,其大小为db转储文件(20110125_SIZE).

因此,如何将其导入SQLite.如果有人使用SQLite3,请帮助我了解.db3文件,以及如何查看它们中的记录.

我有sqlite3 db dump作为dbname.db3,

因此,然后我尝试从php连接此sqllite.这是我从论坛获得的示例代码.

    $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:wampwwwSQLITEindex.php:23 Stack
trace: #0
C:wampwwwSQLITEindex.php(23):
SQLiteDatabase->
_construct(‘C:wampwwwSQL…’)
1 C:wampwwwSQLITEindex.php(15): openDatabase() #2 {main} thrown in
C:wampwwwSQLITEindex.php on line
23

但是,当我使用PDO尝试相同的sqldump时,我就连接了.

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

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

在这里,我不知道此转储中可用的表的列表,因此如何查询它们以列出列表,然后从中获取记录.

请帮助我解决此问题,以便获得连接并从php浏览表.

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

谢谢

解决方法:

在安装了SQLite的系统上,通常还将具有sqlite3命令行程序.可以从命令行或以交互方式使用它转储数据或将其加载到(二进制)数据库文件中.

sqlite3 ./database.file

这将为您提供交互式提示,您可以在其中发出SQL命令或特殊命令(例如.help或.dump).

还有更多的图形工具,但是对于您想做的事情来说,它们可能是过大的.

编辑:看到您的答复(当前在答案部分),似乎您的.db3文件根本不是二进制SQLite3格式,而是可能是转储.那将是一个问题.如果是转储,则必须首先将其加载到适当的数据库文件中.

cat yourdump.sql|sqlite3 ./realdb.db3

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!