gpt4 book ai didi

php - 我如何使用 CodeIgniter 执行 sql 脚本并将数据传递给它?

转载 作者:行者123 更新时间:2023-11-29 04:42:42 24 4
gpt4 key购买 nike

我有一个用于生成数据库的 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);
}

原帖在这里:https://gist.github.com/Relequestual/4088557

关于php - 我如何使用 CodeIgniter 执行 sql 脚本并将数据传递给它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25147099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com