无法连接到DB codeIgniter

时间:2015-07-12 11:21:44

标签: php codeigniter phpmyadmin

我正在尝试自己学习CodeIgniter。但是当我按照本教程中的具体说明进行操作时 http://www.codeigniter.com/user_guide/tutorial/news_section.html

这是我的数据库配置

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'test',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

我收到以下错误:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$db

Filename: pages/about.php

Line Number: 9

Backtrace:

File: /Applications/MAMP/htdocs/CodeIgniter/application/views/pages/about.php
Line: 9
Function: _error_handler

File: /Applications/MAMP/htdocs/CodeIgniter/application/controllers/Pages.php
Line: 18
Function: view

File: /Applications/MAMP/htdocs/CodeIgniter/index.php
Line: 292
Function: require_once


Fatal error: Call to a member function query() on null in /Applications/MAMP/htdocs/CodeIgniter/application/views/pages/about.php on line 9
A PHP Error was encountered

Severity: Error

Message: Call to a member function query() on null

Filename: pages/about.php

Line Number: 9

Backtrace:

2 个答案:

答案 0 :(得分:3)

我在想这是因为你没有自动加载数据库库。

路径: application / config / autoload.php

$autoload['libraries'] = array('database');

为什么显示Message: Undefined property: CI_Loader::$db

答案 1 :(得分:0)

您可以尝试使用控制器或视图加载模型,建议加载控制器......

$ cat 1.txt continent=Asia country=India ;

然后尝试使用:

插入,更新或删除

$this->load->model('News_model','News',true)

$this->News->insert_function($param1,$param2);
希望这有帮助..