Welcome Guest, Not a member yet? Register   Sign In
Trying to get property of non-object?
#1

[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!
#2

[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 ).
#3

[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...
#4

[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;
#5

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

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

[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
#8

[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...




Theme © iAndrew 2016 - Forum software by © MyBB