2013-10-06 64 views
0

我正在为我的Codeigniter应用程序创建一个安装程序模块。Codeigniter:数据库创建后插入数据时出现“表未找到”错误

我正在创建MySQL数据库,它是通过代码的表,并希望在安装过程中将用户凭据插入数据库。就像这样:

enter image description here

我遇到的问题是,创建数据库后,它的表,当我尝试插入用户信息到它给出错误说数据库“表‘用户’没有按不存在“,而表格实际存在。

下面是代码:

$this->load->dbforge(); //Create the database 
$this->install_model->use_sql_string(); //Add the tables from a .sql file 

$this->load->database($database_name); //Load the created database 

$this->install_model->add_the_user($username, $password)); //Insert user data 

数据库并且正在正确创建表。只有最后一行代码才会出现错误。

我不知道我在做什么错在这里。请帮忙!

+0

$ database_name'和它的内容是什么? –

+0

'$ database_name'来自$ _POST(表单),它具有用户输入的数据库名称。 –

+0

我不知道CI中的语法,但在数据库创建后运行查询'USE DBName' – Mihai

回答

1

我想你应该首先加载数据库,比你应该导入.sql文件。 所以表将在加载的数据库中创建。

$this->load->dbforge(); //Create the database 
$this->load->database($database_name); //Load the created database 
$this->install_model->use_sql_string(); //Add the tables from a .sql file 
$this->install_model->add_the_user($username, $password)); //Insert user data 
相关问题