【发布时间】:2015-01-05 04:18:09
【问题描述】:
我真的不知道我的代码有什么问题。到达 $this->load->database();
行时失败代码没有抛出任何异常/错误。
club_controller
public function guardar(){
$data = array(
'id' => $this->input->post('nombredentificador'),
'nombre' => $this->input->post('nombreclub'),
'estado' => True
);
$this->load->model('club_model');
$this->club_model->save($data);
}
club_model
class Club_model extends CI_Model{
function __construct(){
parent::__construct();
$this->load->database();
}
public function save($data){
$this->db->insert('Club', $data);
}
数据库.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'Natacion';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
我使用的是 MySql Workbench,数据库名称是 Natacion
【问题讨论】:
-
如果你自动加载数据库那么它工作吗?另外,当您使用 MySql 工作台时,它是否与数据库连接?如果一切正常,那么您可以使用原始 php 编写一个测试脚本并检查数据库连接是否正常。
标签: php database codeigniter model