CodeIgniter Forums
Undefined property: CI_Loader::$db - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Undefined property: CI_Loader::$db (/showthread.php?tid=10142)



Undefined property: CI_Loader::$db - El Forum - 07-20-2008

[eluser]vickel[/eluser]
I'm new to CI and stuck when trying to connect to mySQL database

my code is like suggested in the userguide:

<?php
$this->load->database();
//$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 />";
}
?&gt;

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


Undefined property: CI_Loader::$db - El Forum - 07-20-2008

[eluser]thinkigniter[/eluser]
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.

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

Cheers


Undefined property: CI_Loader::$db - El Forum - 07-20-2008

[eluser]vickel[/eluser]
thank you a lot, that was the reason !