I assign the result of an SQL query using PDO ( PDO::FETCH_OBJ
) to a variable, and with that variable I access the query values as if it were an object.
Example of an array as an object:
<?php
$obj = (object) array('foo' => 'bar', 'property' => 'value');
echo $obj->foo; // prints 'bar'
echo $obj->property; // prints 'value'
?>
Doubt:
If the query returns me empty and I want to manually assign this key a value and an object value, how do I do it?