Actually, there is a lot of post about this. But even if I checked those, still couldn't find the problem.
DBC class
protected function connect(){
$dns = "mysql:host=" . $this->server . ";dbname=" . $this->database;
$pdo = new PDO($dns, $this->username, $this->password);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
}
and insert function.
public function insert_row($created_at){
$sql = "INSERT INTO empty_rows (created_at) VALUES (?)";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$created_at]);
$id = $this->connect()->lastInsertId();
echo $id;
}
I think it should be return the last inserted Id but, it just returns 0. what am I missing here?