Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
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;
}
}
?>