May 1, 2013 asvignesh 2Comment

Taking backup dump and importing the dump into database can be done very easily using php. In Last posts i explained how to take the backup of Mysql using php

Here is the function to import the sql dump into database

function import_dump($folder_name = null , $file_name) {
$folder_name = 'dumps';
$path = 'assets/backup_db/'; // Codeigniter application /assets
$file_restore = $this->load->file($path . $folder_name . '/' . $file_name, true);
$file_array = explode(';', $file_restore);
foreach ($file_array as $query)
 $this->db->query("SET FOREIGN_KEY_CHECKS = 0");
 $this->db->query("SET FOREIGN_KEY_CHECKS = 1");

6+ years of experience in building data protection, copy data management and storage management applications, automation software and plugins for private and public clouds

Disclaimer :

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. my thoughts and opinions change from time to time… This weblog is intended to provide a semi-permanent point in time snapshot and manifestation of the various memes running around my brain, and as such any thoughts and opinions expressed within out-of-date posts may not the same, nor even similar, to those I may hold today.

2 thoughts on “Import SQL dump to MySQL using Codeigniter

  1. I have some case where the query in mysql dump is something like this:

    INSERT INTO table_name (`field1` , `field2`) values (‘some data’ , ‘some ; data ;’)

    inside the data type varchar or text they have some value with semicolon (;)
    and when we run this code explode(‘;’, $file_restore);
    it got separated into array, how can we prevent this?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.