我如何使用CodeIgniter执行SQL脚本并将数据传递给它? [英] How i can execute a sql script with CodeIgniter and pass data to it?

查看:135
本文介绍了我如何使用CodeIgniter执行SQL脚本并将数据传递给它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于生成数据库的sql脚本,我希望当我按下按钮进行注册时,它会调用sql脚本,但在传递给sql脚本之前,有关如何调用数据库的数据.

I have a sql script to generate a database and I want that when I press the button register it call to the sql script but before pass to the sql script data about how the database will be called.

类似这样:

make_db($ name_db);

make_db($name_db);

推荐答案

根据文件的大小,最好将其转换为Codeigniter模型函数,但是如果不可能,则可以尝试类似的方法exec("mysql < sql_file_name.sql");

Depending on the size of the file, it might be best to convert it into a Codeigniter model function, but if that's not a possibility, you could try something like exec("mysql < sql_file_name.sql");

您似乎想将数据库的名称传递给该函数,因此您可以从文件中取出"CREATE DATABASE what"行,将其作为普通的代码点火器查询运行,然后执行"其余部分该数据库的脚本.

It looks like you want to pass the name of the DB into the function, so you could take the 'CREATE DATABASE whatever' line out of your file, run it as a normal codeigniter query, and then 'exec' the rest of the script for that database.

显然,以这种方式创建数据库通常不是一个好主意,但我不是在这里判断:-)

Obviously creating databases in this way is generally not a great idea, but I'm not here to judge :-)

这篇关于我如何使用CodeIgniter执行SQL脚本并将数据传递给它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆