user3940738
user3940738

Reputation:

Page is blank when attempting to connect to database on CodeIgniter

i have a blank page when trying to connect to my database via CodeIgniter.

Here is my Model

class Forum_data extends CI_Model{
public function forum_post_get(){
    $this->load->database();
      $query = $this->db->get('new_table')->result();
      return $query->result();
}
}

Here is my Controller

public function forum(){
    $this->load->model('forum_data','',TRUE);
    $data['query'] = $this->forum_data->forum_post_get();
    $this->load->view('forum', $data);
}

Here is my View

 <?php
  foreach ($query as $msg) :
    echo $msg->Username;
    echo $msg->Subject;
    echo $msg->Post;
  endforeach;
?>  

And last but not least, here is my database config file

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'admin';
$db['default']['database'] = 'test';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

As stated, all that this returns is a blank page when i type in this url

'http://localhost/ci/index.php/hello/forum'.

(The controller is called hello and the controller function is called forum, because its a forum page i'm trying to make.)

Literally any help is appreciated, i'm new to this.

Upvotes: 1

Views: 370

Answers (1)

Basit
Basit

Reputation: 1840

You are calling result() twice. Change it to:

$query = $this->db->get('new_table'); return $query->result();

Upvotes: 1

Related Questions