in oop neither boom boom, trying to understand why the following error is issued:
Notice: Undefined variable: pdo in C:\MAMP\htdocs\PolitHouse\model\userinfo.php on line 10 Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\MAMP\htdocs\PolitHouse\model\userinfo.php:10 Stack trace: #0 C:\MAMP\htdocs\PolitHouse\model\userinfo.php(21): User->userPview() #1 {main} thrown in C:\MAMP\htdocs\PolitHouse\model\userinfo.php on line 10 Before that I have never used any classes or functions, trying to figure out how it works. The code itself is here:
<?php include_once('../controller/db.php'); class User { public $uid = 1; public function userPview() { $query = ('SELECT politview FROM users WHERE id = :id'); $stmt = $pdo->prepare($query); $stmt->execute(['id' => $uid]); $results = $stmt->fetch(PDO::FETCH_ASSOC); echo $results; } } $user = new User(); echo $user->uid; $user->userPview(); ?>