Mysql
 sql >> Base de données >  >> RDS >> Mysql

Comment puis-je exécuter un script SQL avec CodeIgniter et lui transmettre des données ?

$sql = file_get_contents("update-001.sql");

/*
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);   
}

le message original est ici :https://gist.github.com/Relequestual/4088557