简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM