我想連接我的數據庫在mamp服務器中的代碼點火器。 這裏是我的配置文件如何使用mamp連接數據庫與codeigniter
$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;
我把本地主機: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
請幫我找到解決方案
http://stackoverflow.com/a/4578940/4229270&http://stackoverflow.com/a/11043416/4229270 – Sinto
我會自動加載在自動加載數據庫庫.php – user4419336
我試圖在自動加載數據庫。但顯示相同的錯誤 – nushrat