2

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)

2
  • 1
    Possible duplicate stackoverflow.com/questions/16392828/… Commented Aug 22, 2015 at 8:06
  • I try to create table in a database that is not default database. Commented Aug 22, 2015 at 8:21

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

glad, i could help :)
1

database.php Declare database name in the database.php

This may solve your error!

2 Comments

Please add further details to expand on your answer, such as working code or documentation citations.
Please post your code as text, not as an image. Look here why it's not a good idea to use images or screenshots.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.