Welcome Guest, Not a member yet? Register   Sign In
How to import a sql file in codeigniter?
#4

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.
Reply


Messages In This Thread
RE: How to import a sql file in codeigniter? - by PaulD - 10-27-2015, 11:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB