I want to make a backup of certain tables in my database a .SQL
from php using the framework Codeigniter
Any idea how to do this? I'm in 0
I want to make a backup of certain tables in my database a .SQL
from php using the framework Codeigniter
Any idea how to do this? I'm in 0
CodeIgniter
has a database management class, for this we will use class dbutil
and helper file
(optional) and download
to save the file and download it respectively:
//Hacemos el backup de los datos que nos interesan
$prefs = array(
'tables' => array('tabla1', 'tabla2'), // Listado de tablas.
'ignore' => array(), // Listado de tablas a omitir
'format' => 'zip', // gzip, zip, txt
'filename' => 'backup.zip', // Nombre del fichero - SOLAMENTE PARA FICHEROS ZIP
'add_drop' => TRUE, // Si agregar la sentencia DROP TABLE al backup
'add_insert' => TRUE, // Si agregar la sentencia INSERT al backup
'newline' => "\n" // Salto de línea
);
$backup = $this->dbutil->backup($prefs);
//Cargamos el helper file y generamos un fichero
//Esta parte la usamos solo si deseamos guardarlo en servidor
$this->load->helper('file');
write_file('bk/backup.zip', $backup);
//Cargamos el helper download y forzamos la descarga
$this->load->helper('download');
force_download('backup.zip', $backup);
In the backup options $prefs
if we want to backup the entire db, we simply pass a array
empty instead of tabla1
, tabla2
.
Regards,