我正在使用Codeigniter的DBForge类在该数据库中创建数据库和表.
这是代码:
if ($this->dbforge->create_database('new_db')) {
$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('blog', TRUE);
}
上述代码写在控制器的索引函数内部.执行以下代码时,错误显示为:未选择数据库.有谁知道为什么会这样.任何帮助表示赞赏.