Welcome Guest, Not a member yet? Register   Sign In
Unable connect database
#1

[eluser]Unknown[/eluser]
Hi there, I'm new to CI.

I need some help on connecting to database.
I've configured my database.php configuration file.
Here is it:
Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "123456";
$db['default']['database'] = "ams";
$db['default']['dbdriver'] = "mysqli";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

After that I've created a model:
Code:
<?php

class Places extends Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function get_all()
    {
        return $this->db->get('places')->result();
    }
}

And I've loaded it from my controller:
Code:
<?php

class Index extends Controller
{
    public function __construct()
    {
        parent::__construct();
        
        $this->load->model('places', '', TRUE);
    }
    
    public function index()
    {
        $data = array();
        
        $data['places'] = $this->places->get_all();
        
        $this->layout->page_title = 'Places Management';
        $this->load->view('places/index', $data);
    }
}

On this stage CI says:
Code:
A Database Error Occurred
Unable to connect to your database server using the provided settings.

If I pass the dns as the third parameter, like this:
Code:
<?php
$this->load->model('places', '', 'mysqli://root:123456@localhost/ams');
it connects successfully but it returns an empty array (I'm sure that I have 3 rows in that table).

Please tell me why CI does not use database.php configuration file, and why it returns an empty array if I pass the dns.
#2

[eluser]Unknown[/eluser]
Dear Developers. I've found a bug in the CI database driver.

I don't know where to post the bug. Anyway, I will post it here.

The is that in file system/database/DB_driver.php on line 43 is the code below:
Code:
var $port = '';

The variable $port is passed to mysqli_connect function as the fifth argument.
The problem is that the mysqli_connect function requires the fifth parameter to be NULL instead of empty string if you want to use the default port of mysql server.

I think that the 43 line should be replace like this:
Code:
var $port = NULL

Or it could be moved to the database.php configuration file.



By the way, thanks for so easy to use, clear and clean, etc. framework.
#3

[eluser]Pascal Kriete[/eluser]
This bug is fixed in the trunk version. You can grab the new version of the file here.




Theme © iAndrew 2016 - Forum software by © MyBB