0

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!

4
  • Where is $database_name and what it has in to it ? Commented Oct 6, 2013 at 16:48
  • $database_name comes from $_POST (the form) and it's got the name of database the user entered. Commented Oct 6, 2013 at 16:51
  • I don't know the syntax in CI but after the DB creation run a query USE DBName Commented Oct 6, 2013 at 17:11
  • @Mihai $this->load->database($db_name) does the same thing as USE DBName Commented Oct 6, 2013 at 17:15

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.