PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] can't connect to DB codeIgniter

 January 19, 2022     codeigniter, php, phpmyadmin     No comments   

Issue

I'm trying to learn CodeIgniter by myself. but when I followed the specific instruction from this tutorial http://www.codeigniter.com/user_guide/tutorial/news_section.html

this is my DB config

$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
);

I get the following error:

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:

Solution

I am thinking it is because you did not autoload the database library.

Path: application/config/autoload.php

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

As why Message: Undefined property: CI_Loader::$db shown.



Answered By - Mr. ED
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing