I am trying to connect my database in code igniter in mamp server. here is my config file
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost:3306';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'lalcoresidency';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I put localhost:3306 because port number in mamp server for database is given 3306 .
here is my controller
class Testimonials extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->library('database');
}
public function index(){
$data=array();
$this->load->model('testimonial_model');
$this->load->database();
$data['result']=$this->testimonial_model->get_testimonial();
$this->load->view('testimonials_view',$data);
}
}
here is my model
class Testimonial_model extends CI_Model{
function get_testimonial(){
$this->db->select('*');
$this->db->from('testimonial');
$this->db->order_by("r_id", "desc");
$query=$this->db->get();
return $result=$query->result();
}
}
When i run this code then it showing the following error
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\MAMP\htdocs\lalcoresidency\system\database\DB_driver.php
Line Number: 125
Please help me to find the solution