简体   繁体   中英

creating table in mysql database with codeigniter

I try to create a table with codeigniter in mysql DB with following code:

$posts_fields=array(
        'id'=>array('type' => 'INT','constraint' => 5,'unsigned' => TRUE),
        'title'=>array('type' =>'VARCHAR','constraint' => 100),
        'content'=>array('type'=>'text'),
        'create_time'=>array('type'=>'INT','constraint'=>12));

    $this->dbforge->add_field($posts_fields);
    $this->dbforge->create_table('posts');

but anytime get error "NO DATABASE SELECTED".

how can I select a database to create tables in it?? (this database is not default database)

You can have a look at Codeigniter showing error: No database selected

If you are using different database then use following,

$this->db->query('use db2');

and then put your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM