I am having problems debugging this class. Currently, it "timesout" when implemented as I have shown below (no error message), but it I remove the while statement from the AllNotes method, then the script runs.
Any ideas what I am doing wrong?
$mysqli = new mysqli(MYSQL_SERVER,MYSQL_SERVER_USERNAME,MYSQL_SERVER_PASSWORD);
abstract class Notes {
protected $connection;
protected $data = array();
protected function __construct(mysqli $connection) {
$this->connection = $connection;
}
public function getData() {
return $this->data;
}
}
class OneNote extends Notes {
private $entry;
public function __construct(mysqli $connection, $id) {
parent::__construct($connection);
$this->entry = $id;
$this->getEntry();
}
private function getEntry() {
$query = "SELECT id, title, date, note, timestamp FROM notes WHERE id = ?";
$statement = $this->connection->prepare($query);
$statement->bind_param('s', $this->id);
$statement->execute();
$statement->bind_result($id, $title, $date, $note, $timestamp);
if($statement->fetch()) {
$this->data = array(
'id' => $id,
'col1' => $title,
'col2' => $date,
'col3' => $note,
'col4' => $timestamp
);
}
}
public function getData() {
return $this->data;
}
}
class AllNotes extends Notes {
public function __construct(mysqli $connection) {
parent::__construct($connection);
$this->getEntry();
}
private function getEntry() {
$query = "SELECT id, title, date, note, timestamp FROM notes ORDER BY id DESC";
$statement = $this->connection->prepare($query);
if($statement == false) {
die($this->connection->error);
}
$statement->bind_result($id, $val1, $val2, $val3, $val4);
$statement->execute();
while($statement->fetch()) {
$this->data[$id] = array( //Creating two dimensional array
'id' => $id,
'col1' => $val1,
'col2' => $val2,
'col3' => $val3,
'col4' => $val4
);
}
return $this->data;
}
}
$mysqli->select_db('notes_db');
$notes = new AllNotes($mysqli);
$data = $notes->getData();
foreach($data as $note)
{
echo "<h3 class='title'>".htmlentities($note['title'])."</h3>\n";
echo "<p class='date'>".htmlentities($note['date'])."</h3>\n";
echo "<p class='note'>".nl2br(htmlentities($note['note']))."</h3>\n";
}