Welcome Guest, Not a member yet? Register   Sign In
Undefined property: CI_Loader::$db

I'm new to CI and stuck when trying to connect to mySQL database

my code is like suggested in the userguide:

//$this->db->query('SELECT username FROM users');
$query = $this->db->query('SELECT username FROM users');

foreach ($query->result_array() as $row)
echo $row['username'];
echo "<br>...<br />";

unfortunately I get this error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$db
Filename: views/dbteste.php
Line Number: 12

if anyone could explain me this, I'd apreciate immensly, thanks

My guess is that your doing this in the view and not the controller.

Try putting this code in your controller and commenting out the line to your view.

Because your calling the DB class from outside of the parent class. I think.


thank you a lot, that was the reason !

Theme © iAndrew 2016 - Forum software by © MyBB