我正在尝试在mamp服务器中的代码点火器中连接我的数据库。 这是我的配置文件
$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;
我把localhost:3306,因为数据库的mamp服务器中的端口号给出了3306。
这是我的控制器
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);
}
}
这是我的模特
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();
}
}
当我运行此代码时,它显示以下错误
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
请帮我找到解决方案
答案 0 :(得分:1)
$db['default']['db_debug'] = FALSE;
而不是
$db['default']['db_debug'] = TRUE;