Search code examples
phpsqlitecodeception

How would I perform an sqlite backup through php


I am attempting to use the sqlite backup command through php.

This requires 3 statements

  • Opening the db sqlite3 testing.sqlite
  • Backup the DB .backup testing_backup.sqlite
  • Close sqlite .exit

The exec command doesn't like this as it hangs when the process stays open, I have tried running all three commands together using && to join them but this doesn't work either.

Can anyone help me run the 3 commands through php?

This is an attempt to create a backup file to solve a database locking issue.


Solution

  • The sqlite3 command-line shall can also receive command(s) as parameters.

    Just execute the following command:

    sqlite3 testing.sqlite ".backup testing_backup.sqlite"