Welcome Guest, Not a member yet? Register   Sign In
Problems using dbforge
#1

[eluser]old_guy[/eluser]
I need to create a new dB for each customer. The company I host with (Lunarpages) only allows me to create a dB via their online tools. So after I do that I need to use CI to programmatically to add the required tables.

I call the model from the controller
Code:
$this->load->model('admin/mdl_create_tbls');
$result= $this->mdl_create_tbls->index();
I open the dB I want to add the tables to as follows:
Code:
function __construct()
{
       parent::__construct();
       $config['hostname'] = $hostname;
$config['username'] = $username;
$config['password'] = $password;
$config['database'] = $database_name;
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_unicode_ci";

       $this->load->database($config);
}
function index()
{
  $this->load->dbforge();
                
                 ....use dbforge to build the tables.

}

My problem is not dbforge it works fine. It's that I already have a dB connection and the tables get built in that dB and not the one I try to open per the above. I cannot figure out how to open the new dB and get the tables to be written there.

Any help would be appreciated.
#2

[eluser]TheFuzzy0ne[/eluser]
They have intentionally allowed you to only create databases through their UI, because they have their own structure which they need to enforce. They might need to keep track of how many databases you have created, and also prefix database names with a unique string to prevent naming collisions with the other 999 accounts on the server.

The only way to get around that, is to prefix tables with a unique string to allow them to reside in the same database, or to design your database to allow for single tables, and you instead pull data out using a customer ID, rather than customer specific databases/tables.

However, whatever it is you're trying to do, it would seem that this particular host (or maybe even shared hosts in general), is not suitable for your situation.
#3

[eluser]old_guy[/eluser]
I agree that I'll have to find another hosting solution at some point. But, regardless the problem still exists. I can't get dbforge to work correctly on my development server (xampp) let alone my production server. For whatever reason the code noted in my previous post won't open the dB as defined by the $database_name variable. And I'm at a loss to understand why.
#4

[eluser]TheFuzzy0ne[/eluser]
Are you getting any errors? Do you have error reporting enabled? Are you sure the user has permission to add tables to that database?

It seems to me like there are several potential problems. In the interest of working on one, of potentially several, problems at a time, I would suggest trying to get it to work using root, first. Then you can try to make it work with other users after.




Theme © iAndrew 2016 - Forum software by © MyBB