Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i import SQLite db3 file

Tags:

php

sqlite

Sorry about this question but i never worked with SQLite, and i gone through the SQLite site , downloaded "Precompiled Binaries For Windows" files tried to make them usable for my purpose but i couldnot, i saw with working tutorials with databases,tables.

My tasks is to get data from SQLite and put them into magento mysql DB. So for that i have got the SQLite DB dump file as .db3 file, txt file which has size of db dump file(20110125_SIZE).

So how can i import it into the SQLite. Please if anyone of you worked with SQLite3 help me to understand the .db3 file and how can i see the records from them.

I have got sqlite3 db dump as dbname.db3,

So then i tried to connect this sqllite from php. Here is my sample code which i got it from forum.

    $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;
    } 

But i am getting fatal exception.

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

But when i tried the same sqldump with the PDO , i got connected.

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

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

here i do not know the list of tables available in this dump so how can i query them to list and then getting records from them.

Please help me to solve this issue ti get connected and browse the tables from php.

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

Thanks

like image 205
Elamurugan Avatar asked Dec 09 '25 13:12

Elamurugan


1 Answers

On a system where SQLite is installed, you will usually also have the sqlite3 command line program. It can be used both from the command line or in interactive mode to dump data or load it into a (binary) database file.

sqlite3 ./database.file

This will give you the interactive prompt, where you can issue SQL commands or special commands such as .help or .dump.

There are also more graphical tools, but they are probably overkill for what you want to do.

Edit: seeing your reply (currently in the answer section), it seems that your .db3 file simply is not in the binary SQLite3 format, but instead perhaps a dump. That would be a problem. If it is a dump, you'd have to load it into a proper database file first.

cat yourdump.sql|sqlite3 ./realdb.db3
like image 181
0xC0000022L Avatar answered Dec 12 '25 04:12

0xC0000022L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!