Welcome Guest, Not a member yet? Register   Sign In
multiple database connections
#2

[eluser]Unknown[/eluser]
also tried closing the connection with

Code:
$this->database->close()

and I would add it to the $db array but the database was just crated. a better code snippet:

controller
Code:
makeuser($u,p$);
create_database($s);
create tables($s);
model
Code:
<?php
class Create_model extends Model{

    function Create_model(){
        parent::model();
    }
    function makeuser($user,$pass){
    $config['hostname'] = 'localhost';
    $config['username'] = 'root';
    $config['password'] = 'password';
    $config['database'] = 'project';
    $config['dbdriver'] = 'mysql';
    $config['dbprefix'] = "";
    $config['pconnect'] = FALSE;
    $config['db_debug'] = TRUE;
    $config['cache_on'] = FALSE;
    $config['cachedir'] = "";
    $config['char_set'] = "utf8";
    $config['dbcollat'] = "utf8_general_ci";
    $this->load->database($config,false);    
    $sql='query';
    $this->db->query($sql);
    $this->db->close();
    }
    function create_database($shortname){
        $config['hostname'] = 'localhost';
        $config['username'] = 'root';
        $config['password'] = 'password';
        $config['database'] = 'project';
        $config['dbdriver'] = 'mysql';
        $config['dbprefix'] = "";
        $config['pconnect'] = FALSE;
        $config['db_debug'] = TRUE;
        $config['cache_on'] = FALSE;
        $config['cachedir'] = "";
        $config['char_set'] = "utf8";
        $config['dbcollat'] = "utf8_general_ci";
        $this->load->database($config,false);
    $this->load->dbforge();
    $this->dbforge->create_database($shortname);
    $this->db->close();
    }
    function create_tables($shortname){
    $config['hostname'] = 'localhost';
    $config['username'] = 'root';
    $config['password'] = 'password';
    $config['database'] = $shortname;
    $config['dbdriver'] = 'mysql';
    $config['dbprefix'] = "";
    $config['pconnect'] = FALSE;
    $config['db_debug'] = TRUE;
    $config['cache_on'] = FALSE;
    $config['cachedir'] = "";
    $config['char_set'] = "utf8";
    $config['dbcollat'] = "utf8_general_ci";
    $this->load->database($config,false);
      
       //tables created here goto project database?
}
thanks again,
brandon


Messages In This Thread
multiple database connections - by El Forum - 06-05-2010, 07:59 AM
multiple database connections - by El Forum - 06-05-2010, 08:20 AM
multiple database connections - by El Forum - 06-06-2010, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB