• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to import a sql file in codeigniter?

#6
(10-27-2015, 11:01 AM)PaulD Wrote: Try something like this:

Code:
// Set line to collect lines that wrap
$templine = '';

// Read in entire file
$lines = file('/path/to/file/my_file.sql');

// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;

// Add this line to the current templine we are creating
$templine .= $line;

// If it has a semicolon at the end, it's the end of the query so can process this templine
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
$this->db->query($templine);

// Reset temp variable to empty
$templine = '';
}
}

I got this approach from here: http://stackoverflow.com/questions/19751...-using-php

Works for me. I hope that helps,

Best wishes,

Paul.

my question is database update or replace with new one ? tell more about the flow, should user upload file .sql first then continue with your script above ?
Reply


Messages In This Thread
RE: How to import a sql file in codeigniter? - by freddy - 02-16-2017, 09:13 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.