Every time I try to execute the query it shows:
fatal error: Call to undefined method connect::prepare()
class connect {
private static $instance = null;
private $pdo;
private function __construct() {
try{
$this->pdo = new PDO('mysql:localhost=127.0.0.1;dbname=comment', 'root', '');
} catch(PDOException $e) {
die($e->getMessage());
}
}
public static function getInstance() {
if(!isset(self::$instance)) {
self::$instance = new connect();
}
return self::$instance;
}
}
// this in another page require_once 'connect.php';
class users {
public $pdo;
public function __construct() {
$this->pdo = connect::getInstance();
}
public function insertComment($user_id, $comment_text, $time) {
$sql = "INSERT INTO comments VALUES ('','$user_id', '$comment_text', '$time')";
$this->query = $this->pdo->prepare($sql);
$this->query->execute();
}
}
$user = new users;
$user_id = 10;
$comment_text = 'hello everyone';
$time = date("y/m/d - h:i:s");
$user->insertComment($user_id, $comment_text, $time);