Created
November 16, 2012 16:09
-
-
Save Relequestual/4088557 to your computer and use it in GitHub Desktop.
Run multiple sql queries with CodeIgniter migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"simple_query" is a better choice than query() in this use case.