Skip to content

Instantly share code, notes, and snippets.

@Relequestual
Created November 16, 2012 16:09
Show Gist options
  • Save Relequestual/4088557 to your computer and use it in GitHub Desktop.
Save Relequestual/4088557 to your computer and use it in GitHub Desktop.
Run multiple sql queries with CodeIgniter migrations
/*
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements...
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements.
This small script splits the statements allowing you to run them all in one go.
*/
$sqls = explode(';', $sql);
array_pop($sqls);
foreach($sqls as $statement){
$statment = $statement . ";";
$this->db->query($statement);
}
@mufid
Copy link

mufid commented Dec 4, 2013

Thanks, i am facing the same problem.

Btw, is that a typo?

    $statment = $statement . ";";

@phpcontrols
Copy link

"simple_query" is a better choice than query() in this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment