데이터베이스에 연결할 수 없으며 그 이유를 모르겠습니다.Codeigniter 3 치명적인 오류 : null에 대한 멤버 함수 database()에 대한 호출
나는 stackoverflow를 살펴본 결과이 질문을 발견 : here 그리고 내 문제를 해결하는데 도움이되지 않습니다.
나는 Codeigniter 3의 설명서를 읽었으며 here을 읽고 수동 연결 옵션을 사용했습니다.
는 내 응용 프로그램 컨트롤러에서내 클래스는 그래서 다음과 같습니다
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => 'tasks',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => FALSE
);
을 내가 http://localhost/home.php/welcome
에 액세스 할 때 나는이 얻을 :
이class home extends CI_Controller {
/**
* Class constructor
* Load database lib
*/
public function __construct()
{
$this->load->database();
}
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/home.php/welcome
* - or -
* http://example.com/home.php/welcome/index
*/
public function index()
{
$query = $this->db->get('users');
foreach ($query->result() as $row)
{
var_dump($row->fullName); //testing purpose
}
//$this->load->view('home', $data);
}
내 응용 프로그램에서 데이터베이스 설정이 너무처럼 보인다 오류 :
Fatal error: Call to a member function database() on null in \www\task\application\controllers\home.php on line 12
var_dump ($ this-> load)를 시도했는데 null이고 여기에서 데이터베이스에 연결할 수 없다는 가정하에 가정합니다.
oO 예, 방금 안내 한 후에 발견했습니다. ** 컨트롤러에서 바로 데이터베이스 작업을 작성하는 대신 쿼리를 모델에 배치해야 나중에 쉽게 다시 사용할 수 있습니다. ** 고맙습니다. – Starlays
@ 스즈 레이 즈 오신 것을 환영합니다. 예, 일반적으로 쿼리는 MVC 아키텍처를 사용할 때 모델에 배치해야합니다. – MonkeyZeus