Czolem!
Mam dziwny problem wyskakuje mi error: Using $this when not in object context.
static public function saveToDB($connection){
if ($this->id == -1) { <- Tutaj wyskakuje error
$sql = "INSERT INTO comment(user_id,tweet_id, text, creation_date)
VALUES ('$this->userid','$this->commentId', '$this->text','$this->creation_date')";
$result = $connection->query($sql);
if ($result == true) {
$this->id = $connection->insert_id;
return true;
}
}
}
$com=new Comment();
$com->setUserid(4);
$com->setCommentId(4);
$com->setCreationDate('2017-11-11');
$com->setText('Hakuna Matata, jak pieknie to brzmi');
var_dump($com);
$com->saveToDB($connection);