Codeigniter显示错误:未选择数据库 [英] Codeigniter showing error: No database selected

查看:397
本文介绍了Codeigniter显示错误:未选择数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Codeigniter的DBForge类来创建数据库中的数据库和表。我的代码如下所示:

I am using Codeigniter's DBForge class to create a database and table within that database. My code is as shown below:

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);
        }

上述代码写在控制器的index函数内。执行以下代码时,它会显示错误,未选择数据库。有谁有蚂蚁的想法为什么它发生。任何帮助是赞赏。

The above mentioned code is written inside index function of controller. When the following code is executed, it shows error as, No database selected. Does anyone have ant idea why it is happening. Any help is appreciated.

提前感谢。

推荐答案

/ p>

You need to specify

 $db['default']['database'] = "new_db"; 

在database.php

in database.php

这篇关于Codeigniter显示错误:未选择数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆