CodeIgniter Forums
Database access question - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Database access question (/showthread.php?tid=74144)

Database access question - ronniebel - 07-31-2019

I'm working through the CodeIgniter tutorial called "News section" at this link.

All is set up, including the database "news" table, but when I load my page - - I get a database error.

In my database.php file, I notice that the dbprefix item has this.

'dbprefix' => 'ci_',

When I remove that prefix and just have 

'dbprefix' => '',

then is blank. I'm expecting the news items to appear on that page.

Any ideas what I'm doing wrong?

Here's my News_model code. The error says line 12 which is this. -- $query = $this->db->get('news');

class News_model extends CI_Model {

public function __construct()
public function get_news($slug = FALSE)
if ($slug === FALSE)
$query = $this->db->get('news');
return $query->result_array();

$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();


RE: Database access question - ronniebel - 07-31-2019

Got it working. The issue was in my News.php controller. I copied something wrong from the tutorial. All is working now and the page is reading from the database.

RE: Database access question - Wouter60 - 07-31-2019

Next time, please use the php button on the button bar of the forum's editor, to make your code better readable:
PHP Code:
class News_model extends CI_Model {

 public function __construct()