CobaltBabyBear
CobaltBabyBear

Reputation: 2218

Codeigniter: "Table not found" error when data inserted after database creation

I'm making an installer module for my Codeigniter application.

I'm creating the MySQL database and it's tables through code and want to insert user credentials into db during the installation process. Like this:

enter image description here

The problem I'm having is that after creation of database and it's tables, when I try to insert the user info into the database it gives error saying "The table 'user' doesn't exist" while the table actually exists.

Here is the code:

$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

The database and tables are being created correctly. Only the last line of code gives the error.

I have no idea what I'm doing wrong here. Please help!

Upvotes: 0

Views: 662

Answers (1)

Kapil Jain
Kapil Jain

Reputation: 188

I think You should load the database first, than u should import .sql file. so table will be created in loaded DB.

$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

Upvotes: 1

Related Questions