CodeIgniter Forums
Trying to get property of non-object? - 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: Trying to get property of non-object? (/showthread.php?tid=33310)



Trying to get property of non-object? - El Forum - 08-22-2010

[eluser]kimp[/eluser]
I had the following 3 lines of code working fine on a LAMP install:

$query = $this->db->query('SELECT systemStatus FROM MasterData LIMIT 1');
$row = $query->row();
echo $row->systemStatus;

I then moved the application to my laptop, which is WAMP. Now, those three lines of code are generating an error notice, "trying to get property of non-object".

Firstly, what does the error mean? (Per the codeigniter documentation, the row() function returns an object).

Secondly, why should it start occurring just now? The versions of PHP are almost the same (V5.2.11 on LAMP, V5.2.13 on WAMP), and I did not change the error reporting settings in index.php.

Thanks for your input!


Trying to get property of non-object? - El Forum - 08-22-2010

[eluser]WanWizard[/eluser]
You have to be a bit more specific. Which of these lines generate the error?

If it's the first, your database driver is not loaded. If it's the second, the query has an error (in which case the third also fails).

p.s. using mixed case in table names is not a good idea, that could case problems when migrating from Linux to Windows or the other way around ( export/dump by default creates lowercase table names ).


Trying to get property of non-object? - El Forum - 08-22-2010

[eluser]kimp[/eluser]
Thanks WanWizard

The error is generated by the 3rd line of code: echo $row->systemStatus;

Perhaps it is related to the mixed case table names. I'll give that a try and let you know...


Trying to get property of non-object? - El Forum - 08-22-2010

[eluser]CI_avatar[/eluser]
Try this

Code:
$query = $this->db->query(‘SELECT systemStatus FROM MasterData LIMIT 1’);
//$row = $query->row();
$row = $query->result();
echo $row->systemStatus;



Trying to get property of non-object? - El Forum - 08-23-2010

[eluser]kimp[/eluser]
Thanks all. It was a careless mistake which I have now fixed.


Trying to get property of non-object? - El Forum - 08-23-2010

[eluser]CI_avatar[/eluser]
Good work. keep it up


Trying to get property of non-object? - El Forum - 08-29-2010

[eluser]LeonardoRaygoza[/eluser]
Hi Im having the same problem, when I try to show a value that I get fromo DB I get this: "Trying to get property of non-object" if you resolved the issue, can you please tell me what it the problem?

Thanks


Trying to get property of non-object? - El Forum - 08-29-2010

[eluser]Byrro[/eluser]
[quote author="kimp" date="1282574457"]Thanks all. It was a careless mistake which I have now fixed.[/quote]

If there´s no problem about it, is always nice to post how you fixed it. Maybe in the future it will help someone with the same mistake...