I have a sql request in PHP, the result of this query is put in class variable But when tis request return no result, I would like have a null value in variable, for the moment I have a false boolean returned.
Could you help me ? Thank you
<?php
class test
{
const table_name = 'test_table';
protected $Id;
protected $Nom;
public static function byId($id)
{
$values = array
(
':Id' => $id,
);
$sql = 'SELECT *FROM '.self::table_name.' WHERE Id=:Id';
$QueryPrep = self::getInstance()->prepare($sql);
if(empty($param))
{
$resultQuery = $QueryPrep->execute();
}
else
{
$resultQuery = $QueryPrep->execute($values);
}
if ($resultQuery !=false)
{
$res = $resultQuery->fetchObject(__CLASS__);
return $res;
}
else
{
return false;
}
}
public function get_Id()
{
return $this->Id;
}
}
$cmd_device_id = null;
$cmdDeviceObject = new test();
$cmd_device = $cmdDeviceObject->byId(999);
$cmd_device_id = $cmd_device->get_Id();
echo "cmd_device_id = ".var_dump($cmd_device_id);
?>