cgm225 Posted May 4, 2008 Share Posted May 4, 2008 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->bind_result($id, $val1, $val2, $val3, $val4); $statement->execute(); if($statement->fetch()) { $this->data = array( 'id' => $id, 'col1' => $val1, 'col2' => $val2, 'col3' => $val3, 'col4' => $val4 ); } } 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, note, date, 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('example_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"; } Link to comment https://forums.phpfreaks.com/topic/104059-notesblog-class-timing-out-on-meno-error-given/ Share on other sites More sharing options...
cgm225 Posted May 4, 2008 Author Share Posted May 4, 2008 bump Link to comment https://forums.phpfreaks.com/topic/104059-notesblog-class-timing-out-on-meno-error-given/#findComment-532953 Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 I'm not sure about mysqli but your problem must lay here: private function getEntry() { $query = "SELECT id, title, note, date, 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; } Because it's the only while loop... Link to comment https://forums.phpfreaks.com/topic/104059-notesblog-class-timing-out-on-meno-error-given/#findComment-532955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.