mam mały problem a mianowicie nie wiem jak w poniższym zapytaniu zrobić tak że jeśli Select nic nie zwróci funkcja zwróci 0 a jeśli select coś zwróci to funkcja zwróci tablice $allGalleryRowObject ?. Aktualnie jeśli Select nic nie zwróci mam komunikat Call to a member function fetch() on a non-object in....
Kod
function getGalleryId($id) {
$connect = parent::getConnection();
$allGallery = $connect -> query('SELECT * FROM galeria_grupy WHERE id = '.$id.'');
$allGalleryRowObject = $allGallery->fetch(PDO::FETCH_ASSOC);
if (isset($allGalleryRowObject['id'])) {
return $allGalleryRowObject;
}
else
{
return 0;
}
}
$connect = parent::getConnection();
$allGallery = $connect -> query('SELECT * FROM galeria_grupy WHERE id = '.$id.'');
$allGalleryRowObject = $allGallery->fetch(PDO::FETCH_ASSOC);
if (isset($allGalleryRowObject['id'])) {
return $allGalleryRowObject;
}
else
{
return 0;
}
}