Epower Skrevet 11. januar 2009 Del Skrevet 11. januar 2009 La til prepare i editEntry <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, $memcacheConnection) { if ($memcacheConnection instanceof Memcache) { $this->memcacheConnection = $memcacheConnection; $this->mcConnected = true; } $this->connection = $connection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; if ( $this->mcConnected ) { $this->memcacheConnection->delete('gb-entries'); } } public function deleteEntry( $id ) { if ( is_int( $id ) && $id > 0 ) { $sql = "UPDATE guestbook SET deleted = NOW() WHERE id=?"; $stmt = $this->connection->prepare($sql); $stmt->execute(array($id)); if ( $this->mcConnected ) { $this->memcacheConnection->delete( 'gb-entries' ); } } } public function editEntry($id) { if(is_int($id) && $id > 0) { $sql = "UPDATE guestbook SET message=? WHERE id=?"; $stmt = $this->connection->prepare($sql); if ( $this->mcConnected ) { $this->memcacheConnection->delete( 'gb-entries' ); } } } public function fetchEntries(array $options = array()) { if ( $this->mcConnected ) { $entries = $this->memcacheConnection->get( 'gb-entries' ); if ( $entries !== false ) { return unserialize( $entries ); } } $sql = "SELECT /*SQL_CACHE*/ id, author, email, website, message, created FROM guestbook WHERE !deleted ORDER BY created DESC;"; $stmt = $this->connection->prepare($sql); $stmt->execute(); $this->entries = $stmt->fetchAll(PDO::FETCH_CLASS, 'GuestbookEntry'); if ( $this->mcConnected ) { $this->memcacheConnection->set( 'gb-entries', serialize( $this->entries ) ); } } public function __destruct () { for ( $i = 0, $iMax = count ( $this -> entries ); $i < $iMax; $i++ ) { if ( empty ( $this -> entries[$i] -> id ) ) { $sql = "INSERT INTO guestbook (author, email, website, message, ip) VALUES (?,?,?,?,INET_ATON(?))"; $stmt = $this->connection->prepare($sql); $stmt->execute(array( $this->entries[$i]->author, $this->entries[$i]->email, $this->entries[$i]->website, $this->entries[$i]->message, $_SERVER['REMOTE_ADDR'] )); } } } } class GuestbookEntry { public $id; public $author; public $email; public $website; public $message; public $date; public $ip; public function __set($key, $value) { if (isset($this->$key)) { $this->$key = $value; } } } Lenke til kommentar
Wackamole Skrevet 23. januar 2009 Del Skrevet 23. januar 2009 ingen som vil fortsette? Lenke til kommentar
JohndoeMAKT Skrevet 23. januar 2009 Del Skrevet 23. januar 2009 Hadde muligens vært mer interesse dersom det ble laget noe du ikke trengte tidsmaskin for å bruke. Lenke til kommentar
Zic0 Skrevet 19. juli 2009 Del Skrevet 19. juli 2009 (endret) k Endret 12. august 2010 av Zic0 Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå