Do I use a class?

Guys, I have created a class report. True created the file itself logs.phpthat uses my class and there are no gross errors in the class itself?
class Logs
{
 protected $db;
 public $id;
 public $text;

 public function __construct($db){
 $this->db = $db;
}

 public function create($text){
 $query = "INSERT INTO `logs` (`date`, `text`) VALUE (NOW(), ?)";
 $stmt = $db->prepare($query);
if($stmt->execute(array($text))){
 return true;
}else{
 return false;
}
}

 public function delete($id){
 $stmt = $db->prepare("DELETE FROM `logs` WHERE `id` = ?");
if($stmt->execute(array($id))){
 return true;
}else{
 return false;
}
}

 public function getAll($id = 0){
if(!empty($id)){
 $query ="SELECT * FROM `logs` WHERE `id` = '".intval($id)."'";
}else{
 $query ="SELECT * FROM `logs`";
}
 $stmt = $db->query($query);
 return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

//logs.php the ISSUE is MORE TO THIS part of the CODE

$logs = new Logs(DB:instance());

if(isset($_POST['add'], $_POST['text'])){
if($logs->create($_POST['text'])){
 echo 'Record added';
}else{
 echo 'Error adding';
}
}

if(isset($_GET['del_id'])){
if($logs->delete($_GET['del_id'])){
 echo 'Entry deleted';
}
}

echo '<h2>All reports</h2>';
echo '<ul>';
foreach($logs->getAll as $v){
 echo '<li>'.$v['date'].': '.$v['text'].'</li>';
}
echo '</ul>';
June 7th 19 at 14:49
3 answers
June 7th 19 at 14:51
Briefly looking at:
1. Why the class is declared public attributes id and text if they are not used anywhere?
2. Everywhere you are using $db->prepare, but the local variable $db is not initialized. In this code, You must refer to an attribute class, i.e. $this->db->prepare
3. Why in every method to check this check
if($stmt->execute(array($text))){
 return true;
}else{
 return false;
}

but what sense in it if $stmt->execute and so returns a boolean, it is easier to write just
return $stmt->execute();
4. Anyway in case of an error it is better that a method does not return false but an exception was thrown, and the clients of the class already on it somehow reacted
5. In the method getAll parameter $id is better to put a default value of null
And at the expense of attributes, I honestly do not know. When creating classes usually say necessary properties to create. But in this example I simply created a class in which he really did not understand why these properties) - thelma commented on June 7th 19 at 14:54
June 7th 19 at 14:53
1) the class name in the plural, no one does. just Log.
2) use PSR-3 Logger Interface, and not a city bike.
3) design type
if($stmt->execute(array($text))){
 return true;
}else{
 return false;
 }
you can always reduce to
return (bool)$stmt->execute(array($text));
June 7th 19 at 14:55
Thanks a lot guys. And still the question a little more about the second part of the script. It is normally done, or crooked?)

Find more questions by tags PHPOOP