Khoaxt
Khoaxt

Reputation: 1

Can not load database

I have a project using CodeIgniter framework. In model class, i try to load data from the database, but the browser return a very very strange result. The page return look like:

load->database('demo', TRUE);}function getData(){...} 
(and follow are very much signs like China character +_+)

Below is the content of user_model.php:

class User_model extends CI_Model 
{
   function __construct() 
   {
       parent::__construct();
       #Line 6: $CI =& get_instance();
       $this->load->database('demo', TRUE);
   }

    function getData()
    {
       $query = $this->db->query("select * from user");

       if ($query->num_rows() < 0)
          show_error('Database is empty!');
       else
          return $query->result();
    }
}

I googled very much and got some solutions, but none of them can solved my problem.

Please help me, i've lost 2 days for this. I can't explain how the China character can display there. It's make me crazy.

P/s: My environment: Window XP SP3 / WAMP server 2.1 / CodeIgniter 2.0.2 All configurations completed and system can run welcome message smoothly.

Upvotes: 0

Views: 262

Answers (2)

kopaty4
kopaty4

Reputation: 2296

class User_model extends CI_Model 
{
   function __construct() 
   {
       parent::__construct();
       #Line 6: $CI =& get_instance();
       $DB1 = $this->load->database('demo', TRUE);
   }

    function getData()
    {
       $query = $DB1->query("select * from user");

       if ($query->num_rows() < 0)
          show_error('Database is empty!');
       else
          return $query->result();
    }
}

Upvotes: 0

GolezTrol
GolezTrol

Reputation: 116100

If your code is visible in your browser, it seems to me that the script is just output instead of executed. If others php scripts run fine, you probably forgot the opening <?php tag in user_model.php.

Upvotes: 1

Related Questions