I'm using MySQL PDO class. I want to get a row. it successfully completes this code. But if there is no data. I get 'Notice: Trying to get property of non-object in PDO'
<?php
...
public static function getRow($query, $bindings = null)
{
if(!$stmt = self::query($query, $bindings))
return false;
$result = $stmt->fetch();
return $result;
}
$page = DB::getRow('SELECT * FROM page WHERE id = "homepage" ');
echo $page->content;
?>
if available id data "homepage". output:
"Homepage bla bla...";
if there is no data. output:
"Notice: Trying to get property of non-object in /var/www/vhosts/kkkk.com/httpdocs/index.php on line 139"
How do I fix it ?
"I want a solution within the function"