CodeIgniter & DBForge - Create Database and Tables
$this->db->query('use db2');
$this->db->query('use DB1');
if ($this->dbforge->create_database('my_db_test'))
{
try{
$current_database = "my_db_test";
$this->db->database = $current_database;
$this->db->close();
$config['hostname'] = "localhost";
$config['username'] = "root";
$config['password'] = "";
$config['database'] = $current_database;
$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);
$fields = array(
'blog_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'blog_title' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'blog_author' => array(
'type' =>'VARCHAR',
'constraint' => '100',
'default' => 'King of Town',
),
'blog_description' => array(
'type' => 'TEXT',
'null' => TRUE,
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('blog_id', TRUE);
$this->dbforge->create_table('ipn_log', TRUE);
}catch(Exception $e){
echo $e->getMessage();die;
}
}
}