<?php
/* The Comment Class */
class Comment {
private $mysqli;
private static $mycomment = null; //It's means that I can add more and more comments
/* Connecting... */
public function __construct() {
$this->mysqli = new Mysqli('localhost', 'root', '', 'cms');
$this->mysqli->query("SET NAMES 'utf8'");
}
public static function getComment() {
if(self::$mycomment === null) self::$mycomment = new Comment();
return self::$mycomment;
}
/*Comment Functions*/
public function viewComment($name, $comment)
{
$result_set = $this->mysqli->query("SELECT * FROM `articles` ORDER BY `id` DESC");
while($result = $result_set->fetch_array()):
print "$result[name] : $result[text_comment]<br>";
endwhile;
}
public function addComment($name, $comment)
{
if($name =="") return false;
if($comment =="") return false;
$this->mysqli->query("UPDATE `articles` SET `name` = '$name', `text_comment` = '$comment' WHERE(`id` = '$id')");
}
/* Closing the connection */
public function __destruct() {
if($this->mysqli) $this->mysqli->close();
}
}
?>