在codeigniter 3.0.6版中创建安装表单时,无法创建数据库运行时

时间:2016-09-21 12:16:58

标签: php codeigniter mysqli codeigniter-2 codeigniter-3

我尝试创建CodeIgniter-Installer方法,当我第一次运行应用程序时,应该动态创建数据库。我有下面的代码,它在codeigniter版本2.2.0中运行良好,但在版本3.0中得到错误。错误是" mysqli :: real_connect():( HY000 / 1049):未知数据库"。

$这 - >负载>数据库($ config_db);不工作

if(!is_array($config_db))
    {
        $config_db = array();
        $config_db['hostname'] = $this->input->post('host');
        $config_db['username'] = $this->input->post('user');
        $config_db['password'] = $this->input->post('password');
        $config_db['database'] = $this->input->post('database');
        $config_db['dbdriver'] = 'mysql';   

    }
    // Unset any existing DB information
    unset($this->db);

    // Explicitly set debugging to FALSE to avoid CI throwing errors if its wrong
    $config_db['db_debug'] = FALSE;

    // load based on custom passed information
    $this->load->database($config_db);

    if (is_resource($this->db->conn_id) OR is_object($this->db->conn_id))
    {
        // There is a connection

        $this->load->dbutil();

        // Now then, does the DB exist?
        if ($this->dbutil->database_exists($this->db->database))
        {
            // Connected and found the db. Happy days are here again!
            return TRUE;
        }
        else
        {
            $this->load->dbforge();

            if ($this->dbforge->create_database($this->db->database))
            {
                return TRUE;
            }
            else
            {
                return FALSE;
            }
        }
    }
    else
    {
        return FALSE;
    }

0 个答案:

没有答案