<? 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, $text ); try { $entryStatement->execute( $formData ); // echo "Entry successfully added. Go to All Entries to view."; } 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"; //SELECT 'columnName' AS 'aliasName' //this is SQL Aliases: temporarily rename a table or column heading //so that it's more readable. $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; } } ?>