Welcome Guest, Not a member yet? Register   Sign In
adding new table on other new database created
#1

[eluser]arie kadarusman[/eluser]
Hello guys, I hope you can help me.
My problem is all about database. I tried all my best but i give up. Here’s my contrroler code

Code:
class Cadminlogin extends CI_Controller
{
function __construct()
{
  parent::__construct();

  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->load->library('security');
  $this->load->library('tank_auth');
  $this->lang->load('tank_auth');
}

function newdatabases()
{
  if ($this->tank_auth->is_logged_in(FALSE)) {      // logged in, not activated
   redirect('cadminlogin/send_again/');

  }  else {
   $this->form_validation->set_rules('databasename', 'Database Name', 'trim|required|xss_clean');
  
  $data['errors'] = array();
  
   if ($this->form_validation->run()) {        // validation ok
    if ($this->tank_auth->create_database(
      $this->form_validation->set_value('databasename'))) {  // success
     redirect('cadminlogin/register/');

    } else {              // fail
     $errors = $this->tank_auth->get_error_message();
     foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
    }
   }
  
}



and i add some code ini tank auth library

Code:
class Tank_auth
{
private $error = array();

function __construct()
{
  $this->ci =& get_instance();

  $this->ci->load->config('tank_auth', TRUE);

  $this->ci->load->library('session');
  $this->ci->load->database();
  $this->ci->load->model('tank_auth/users');
  
  // Try to autologin
  $this->autologin();
  

}
function create_database($databasename)
{
  return $this->ci->users->create_DB($databasename);
}

}


then here model.

Code:
class Users extends CI_Model
{
private $table_name   = 'users';   // user accounts
private $profile_table_name = 'user_profiles'; // user profiles

function __construct()
{
  parent::__construct();

  $ci =& get_instance();
  $this->table_name   = $ci->config->item('db_table_prefix', 'tank_auth').$this->table_name;
  $this->profile_table_name = $ci->config->item('db_table_prefix', 'tank_auth').$this->profile_table_name;
}


function create_DB($databasename)
        {
        $this->load->dbutil();
    $dbs = $this->dbutil->list_databases();

    foreach($dbs as $db)
    {
        echo $db;
    }    
    
    if ($this->dbforge->create_database($databasename))
        {
//  $table_name   = 'mahasiswa';
$this->db->close();
  $this->create_Structure_User($databasename);
       echo 'Database created!';
       }
    }
    
function create_Structure_User($databasename)
    {

         $this->load->dbutil(); // note - $this->load->dbforge(); doesnot work
    if ($this->dbutil->database_exists($databasename))
{
$new_db = $this->load->database($databasename);
  $fields = array(
                        'nickname' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '40'
                    ),
                
              'password' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '40'
                    ),
                'realName' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '40'
                    ),
              
                    'country' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '40'
                    ),
                 'timezone' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '40'
                    ),
                   'phone' => array(
                                                 'type' => 'VARCHAR',
                                                 'constraint' => '40'
                    ),
                    
                    'notes' => array(
                                                 'type' => 'TEXT'
                                                   )
                );
  $this->dbforge->add_field($fields);
        $this->dbforge->create_table('mahasiswa', TRUE);
  $this->db->close();

}

}
the problem is, i have database name login, so i want create new database and create new table in new database i create .. database create success but the table created on database login.. not in new database i created.

sorry my english bad, help please... how to do it adding new table to database i new created... thanks before
#2

[eluser]benton.snyder[/eluser]
You can define "database groups" in your application->config->database which allows you to connect to multiple databases. Check out the user guide for examples: http://ellislab.com/codeigniter/user-gui...cting.html
#3

[eluser]boltsabre[/eluser]
Are you trying to create a new database, with a new table, for each person who registers on your site?

If so.... WHY?
One database, one "users" table, insert a new row for each new member.
#4

[eluser]arie kadarusman[/eluser]
[quote author="benton.snyder" date="1353339539"]You can define "database groups" in your application->config->database which allows you to connect to multiple databases. Check out the user guide for examples: http://ellislab.com/codeigniter/user-gui...cting.html[/quote]

i checked that but i must add config new connect manually.. so when i created new database i must config manually again for new connection database.. i want create new database and new table on the database on the same time.. is that how to do it?
#5

[eluser]arie kadarusman[/eluser]
[quote author="boltsabre" date="1353339582"]Are you trying to create a new database, with a new table, for each person who registers on your site?

If so.... WHY?
One database, one "users" table, insert a new row for each new member.[/quote]


no, the database i want create just admin can create , then the table created too but, in my problem database created but the table create on another database not in new database created...




Theme © iAndrew 2016 - Forum software by © MyBB