Witam,
Mam klasę obsługującą PDO:
connection.class.php:
class Connection{
public function __construct(){
try {
$db = new PDO('mysql:host=localhost;dbname=xxx', 'xxx', 'xxx');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage(); }
}
^ To tylko fragment potrzebny
I klase obsługującą renderowanie planu:
schedule.php
<?php
require('../pdo.class.php');
//Plik wyciągający dane ramówki
class ScheduleRendering extends Connection{
public function fetch($db){
$this->day = $_GET['day'];
$stmt = $db->prepare('SELECT * FROM schedule WHERE day = ?');
$stmt->bindValue(1, $this->day);
$stmt->execute();
$contents = $stmt->fetchAll();
return $contents;
}
public function render($contents){
$this->row = 0;
$this->rows = '';
foreach($contents as $row){
$this->rows .= '<tr><td>'.$row['name'].'</td><td>'.$row['presenter'].'</td><td>'.$row['times'].' - '.$row['timed'].'</td></tr>';
}
$rows = $this->rows;
return $rows;
}
}
$db = new Connection();
$schedule = new ScheduleRendering();
$schedule->fetch($db);
$schedule->render($contents);
?>
No i mam taki problem, bo z pliku schedule wywala mi Fatal Error:
Fatal error: Call to undefined method Connection::prepare() w linii 12 plik schedule.php
Jak przekazać handler $db do metody fetch klasy Schedule??