Filippos
Filippos

Reputation: 457

Sqlite3 dump database through PHP

I want to be able to dump a whole sqlite database to a file (database.sql) so as to use it as a backup. The problem is that exec() in PHP doesn't seem to run correctly the ".dump" command as it gives only "COMMIT;" as a result and not the whole text:

$db = new SQLite3('checks_db.db');
$results=$db->exec('.dump');
$content=$results->fetchArray();

If I run it from sqlite3 it gives both the schema and the insert insrtuctions with the data. Perhaps I should also mention that the database has 777 permissions. Can anyone write an example of the syntax of the '.dump' command in php-sqlite3?

Upvotes: 2

Views: 4696

Answers (1)

CL.
CL.

Reputation: 180192

The SQLite database does not have a .dump command.

The sqlite3 command-line shell has a .dump command. To be able to use it, you would have to execute that tool; something like this:

exec('sqlite3 /some/where/checks_db.db .dump', $output);

The easiest way to make a backup would be to copy the database file itself, but using the shell's .backup command would be safer.

Upvotes: 5

Related Questions