
class.news.php
<?php class Newsy{ private $category; public function _construct($category){ $this->category=$category; } public function getData(){ include 'pdo.php'; $result=$pdo->query("SELECT * FROM '$this->category' ORDER BY id DESC"); while($dane = $result->fetch_object()){ } } } ?>
pdo.php
<?php $dsn = 'mysql:dbname=test;host=localhost;'; $user = 'root'; $password = ''; try { $pdo = new PDO($dsn, $user, $password); } catch (PDOExeptions $e){ } ?>
index.php
<?php include "class.news.php"; $lay_out = new Newsy('news'); $lay_out->getData(); ?>
Błąd który mi wywala to:
Fatal error: Call to a member function fetch_object() on a non-object in D:\xampp\htdocs\oop1\class.news.php on line 16