0

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

4
  • stackoverflow.com/a/4578940/4229270 & stackoverflow.com/a/11043416/4229270 Commented May 14, 2016 at 8:00
  • I would auto-loading the database library in autoload.php Commented May 14, 2016 at 8:02
  • I tried to database in autoload .but showing the same error Commented May 14, 2016 at 8:03
  • Please help me for this error Commented May 14, 2016 at 8:12

1 Answer 1

1
$db['default']['db_debug'] = FALSE;

Instead of

$db['default']['db_debug'] = TRUE;
Sign up to request clarification or add additional context in comments.

1 Comment

UR most wellcome nushrat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.