<?php try { class DAJ { var $daj; PDO $pdo; PDO $stmt; public function _construct($wers){ $this->$daj = $wers; $this->$pdo = new PDO('mysql:host=localhost;dbname=xxxxxxx', 'xxxxxx', 'xxxxxxxxx'); $this->$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->$stmt = $pdo -> prepare('SELECT * FROM `glowna` WHERE `gl_id` = :ida'); $this->$stmt -> bindValue(':ida', $this->$daj, PDO::PARAM_INT); $this->$stmt -> execute(); if($row = $this->$stmt -> fetch()) { echo '<br><a href="ksiega.php?strona='.$row['gl_id'].'" > '.$row['gl_normal'].' : .$row['gl_cecha'].'</a>'; } else { echo '<hr/><p>Przepraszamy, podany rekord nie istnieje!</p>'; } $stmt -> closeCursor(); catch(PDOException $e) { echo 'Wystapil blad biblioteki PDO: ' . $e->getMessage(); } } } } ?>
konstruktor jako argument otrzymuje zmienną i na jej podstawie przeszukując beze danych wypluwa odpowiedni wynik w postaci obiektu