[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.