我有一个 SQL 脚本来生成数据库,我希望当我按下按钮时注册它调用 SQL 脚本,但在传递到 SQL 脚本有关如何调用数据库的数据之前。
有些像这样:
make_db($name_db);
最佳答案
$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);
}
关于php - 使用 CodeIgniter 从 .sql 文件执行 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25147099/