I keep getting this error while using the PDO FETCH OBJ and I can’t seem to figure it out. Any help would be greatly appreciated. Thanks.
Error:
Severity: Notice
Message: Trying to get property of non-object
Code Sample:
$database = $this->getDb();
$statement = $database->prepare(‘SELECT company_name, contact_name, address1, address2, city, state, zip, tax_id FROM client_details WHERE id = :id’);
$statement->execute(array(‘:id’ => $id));
$dbRow = $statement->fetch(\PDO::FETCH_OBJ);
// Then so I can access my columns
$dbRow->company_name;
and etc…
Presuming that the error is from the fetch()
line, that suggests that the query has not executed for some reason, or maybe it has returned no rows. Also presuming the \ before PDO::FETCH_OBJ
isn’t in the real code, though I’m not sure whether it would matter.
If it’s on the
$dbRow = $statement->fetch(\PDO::FETCH_OBJ);
line, then your query failed. You have to set PDO in exception mode to get notified of the reason.
if it’s on the
$dbRow->company_name;
line, then your query simply returned no rows
Thank you for the reply. Giving it a try.
Yes, it wasn’t returning any rows. Taking a look. Thank you for your reply.
system
Closed
December 12, 2016, 8:11am
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.