[UPDATE] Ik heb al een oplossing gevonden.

Ik probeer in mijn classes gebruik te maken van PDO connectie, maar krijg telkens deze foutmelding: Notice: Undefined property: Bootstrap::$db in E:\root\2013\AVDirect\libs\Question.php on line 32

Op regel 32 staat:
$this->db->select("SELECT `q_id`, `q_sub`, `q_title`, `q_content`, `q_explanation`, `a_type` FROM `question` WHERE `q_id` = '$q_id'");


Bootstrap.php:

<?php

class Bootstrap {

	function __construct() {

		// Get URL pieces
		if(isset($_GET['url'])) {
			$url = Functions::getUrlPieces($_GET['url']);
		} else {
			$url[0] = '';
		}

		// Include homepage if no specific page was requested
		if (empty($url[0])) {
			require 'pages/index.php';
			return false;
		}

		// If specific page was requested, check whether that page exists
		// If the page does exist, include the page
		// If the page does not exist, show errorpage.
		$file = 'pages/' . $url[0] . '.php';
		if (file_exists($file)) {
			require $file;
		} else {
			require 'pages/404.php';
		}
	}
}
?>


Index.php:

<?php
$pdo = new PDO('mysql:host=localhost;port=3307;dbname=' . DB_NAME, DB_USER, DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$result = $pdo->query('SELECT * FROM answer WHERE q_id = 1');
# Map results to object
$result->setFetchMode(PDO::FETCH_CLASS, 'Question');

while ($question = $result->fetch()) {
	# Call our custom full_name method
	echo $question->full_name();
}
?>


Question.php:

<?php
class Question extends Database {

	public $db = "";
	public $q_id = "";

	public function __construct() {
		$this->db = new Database(DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASS);
	}
	
	public function full_name() {
		return 'Nummer: ' . $this->q_id;
	}

public function q_data_from_q_id($q_id) {
    $this->db->select("SELECT `q_id`, `q_sub`, `q_title`, `q_content`, `q_explanation`, `a_type` FROM `question` WHERE `q_id` = '$q_id'");
}
?>


Database.php:

<?php
class Database extends PDO {

	public function __construct($DB_TYPE, $DB_HOST, $DB_PORT = 3307, $DB_NAME, $DB_USER, $DB_PASS) {
		parent::__construct($DB_TYPE . ':host=' . $DB_HOST . ';port=' . $DB_PORT . ';dbname=' . $DB_NAME, $DB_USER, $DB_PASS);

		//parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTIONS);
	}
	
	/**
	 * select
	 * @param string $sql An SQL string
	 * @param array $array Parameters to bind
	 * @param constant $fetchMode A PDO Fetch mode
	 * @return mixed
	 */
	public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC) {
		$sth = $this->prepare($sql);
		foreach ($array as $key => $value) {
			$sth->bindValue("$key", $value);
		}
		$sth->execute();
		return $sth->fetchAll($fetchMode);
	}
}
?>

Reageren