Newer
Older
class Blog_Entry_Table {
//Establish connection to database with PDO
private $db;
public function __construct ( $db ) {
$this->db = $db;
}
//Insert new entries
public function saveEntry ( $title, $text ) {
$entrySQL = "INSERT INTO blog_entry (title, text) VALUES (?, ?)";
$entryStatement = $this->db->prepare( $entrySQL );
$formData = array( $title, $entry );
try {
$entryStatement->execute( $formData );
} catch (Exception $e){
$msg = "<p>You tried to run this sql: $entrySQL<p>
<p>Exception: $e</p>";
trigger_error($msg);
}
}
//Get all entries
public function getAllEntries () {
$entrySQL = "SELECT id, title, SUBSTRING(text, 1, 140) AS intro FROM blog_entry";
$statement = $this->db->prepare( $entrySQL );
try{
$statement->execute();
} catch (Exception $e){
$msg = "<p>You tried to run this sql: $entrySQL<p>
<p>Exception: $e</p>";
trigger_error($msg);
}
return $statement;
}
}
?>