JohndoeMAKT Skrevet 22. desember 2008 Del Skrevet 22. desember 2008 La til innskriving av ucachet resultat i MC. <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; } public function fetchEntries(array $options = array()) { if ( $this->mcConnected ) { $entries = $this->memcacheConnection->get( 'gb-entries' ); if ( $entries !== false ) { return unserialize( $entries ); } } $sql = "SELECT * FROM guestbook;"; $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 entries (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 $mail; public $website; public $message; public $date; public $ip; public function __set($key, $value) { if (isset($this->$key)) { $this->$key = $value; } } } ?> Lenke til kommentar
Epower Skrevet 22. desember 2008 Del Skrevet 22. desember 2008 La til cache i addEntry <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; if ( $this->mcConnected ) { } } public function fetchEntries(array $options = array()) { if ( $this->mcConnected ) { $entries = $this->memcacheConnection->get( 'gb-entries' ); if ( $entries !== false ) { return unserialize( $entries ); } } $sql = "SELECT * FROM guestbook;"; $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 entries (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 $mail; public $website; public $message; public $date; public $ip; public function __set($key, $value) { if (isset($this->$key)) { $this->$key = $value; } } } ?> Lenke til kommentar
JohndoeMAKT Skrevet 22. desember 2008 Del Skrevet 22. desember 2008 Spørsmålet er om cache skal slettes eller oppfriskes når en ny oppføring kommer inn. Jeg stemmer sterkt for sletting. Jeg horet opp en SQL-spørring. <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; if ( $this->mcConnected ) { } } 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 entries (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 $mail; public $website; public $message; public $date; public $ip; public function __set($key, $value) { if (isset($this->$key)) { $this->$key = $value; } } } ?> Lenke til kommentar
Epower Skrevet 23. desember 2008 Del Skrevet 23. desember 2008 (endret) La til sletting av memcache i addEntry <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; 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 entries (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 $mail; public $website; public $message; public $date; public $ip; public function __set($key, $value) { if (isset($this->$key)) { $this->$key = $value; } } } ?> Endret 23. desember 2008 av Eirikkkkkk Lenke til kommentar
Wackamole Skrevet 25. desember 2008 Del Skrevet 25. desember 2008 c'mon, har litt igjen nå, vil gjerne lære meg dette !! - og hvis noen kunne forklart hva det dem legger ut gjør så hadde det vært supert! Lenke til kommentar
JohndoeMAKT Skrevet 25. desember 2008 Del Skrevet 25. desember 2008 La til metode deleteEntry(). <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; if ( $this->mcConnected ) { $this->memcacheConnection->delete('gb-entries'); } } public function deleteEntry( $id ) {} 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 entries (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 $mail; public $website; public $message; public $date; public $ip; public function __set($key, $value) { if (isset($this->$key)) { $this->$key = $value; } } } ?> Lenke til kommentar
Epower Skrevet 25. desember 2008 Del Skrevet 25. desember 2008 Fiksa noen små feil <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } public function addEntry(GuestbookEntry $entry) { $this->entries[] = $entry; if ( $this->mcConnected ) { $this->memcacheConnection->delete('gb-entries'); } } public function deleteEntry( $id ) {} 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
Rinox Skrevet 26. desember 2008 Del Skrevet 26. desember 2008 Morsom konkurranse Kanskje gjøre det obligatorisk å legge til en kommentar i koden sin? Kanskje bare jeg som ville syntes det var fint... Lenke til kommentar
JohndoeMAKT Skrevet 26. desember 2008 Del Skrevet 26. desember 2008 (endret) Dersom du mener //-kommentarer er jeg helt uenig. Inlinekommentarer er ikke nødvendig for noe så banalt som.. hva er det igjen vi lager? La til en if i deleteEntry(); <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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 ) {} } 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; } } } ?> Endret 26. desember 2008 av JohndoeMAKT Lenke til kommentar
Epower Skrevet 26. desember 2008 Del Skrevet 26. desember 2008 Prøvde meg på en sql i deleteEntry <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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 = "DELETE FROM guestbook WHERE id='?'"; } } 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
PS_CS4 Skrevet 26. desember 2008 Del Skrevet 26. desember 2008 Ryddet litt i koden <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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 = "DELETE FROM guestbook WHERE id='?'"; } } 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
Jonas Skrevet 26. desember 2008 Del Skrevet 26. desember 2008 (endret) Jeg er vanligvis en som liker mye luft i koden, men ærlig talt - linjebreak mellom klassevariablene? Hvorfor i all verden indeterer du alle funksjonene i klassen et hakk mer enn vanlig? Og hvorfor to linjer mellom starten på en klasse og første linje i den klassen? Endret 26. desember 2008 av Jonas Lenke til kommentar
Epower Skrevet 27. desember 2008 Del Skrevet 27. desember 2008 Fortsatte litt med deleteEntry, jeg <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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 = "DELETE FROM guestbook WHERE id='?'"; $stmt = $this->connection->prepare($sql); } } 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 27. desember 2008 Del Skrevet 27. desember 2008 @Eirikkkkkk: Foreslår at man oppdaterer raden "Deleted" med 0 eller 1 (1 hvis slettet), istedenfor og slette innlegget fra databasen ^^ - men siden jeg ikke kan en dritt om OOB(?), så vil jeg bare fremme forslaget istedenfor og prøve meg på koden Lenke til kommentar
Epower Skrevet 27. desember 2008 Del Skrevet 27. desember 2008 Ok, tenkte ikke over det.. Sånn da: <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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='1' WHERE id='?'"; $stmt = $this->connection->prepare($sql); } } 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
JohndoeMAKT Skrevet 27. desember 2008 Del Skrevet 27. desember 2008 deleted er et date_time felt med vilje. <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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); } } 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
Epower Skrevet 27. desember 2008 Del Skrevet 27. desember 2008 <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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)); } } 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
JohndoeMAKT Skrevet 27. desember 2008 Del Skrevet 27. desember 2008 La til en blokk for flushing av cache i deleteEntry. <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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 ) {} } } 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
Epower Skrevet 29. desember 2008 Del Skrevet 29. desember 2008 La til flushing av memcache i deleteEntry. <?php class Guestbook { private $numEntriesPerPage = 10; private $connection; private $entries; private $memcacheConnection; private $mcConnected; public function __construct(PDO $connection, Memcache $memcacheConnection) { $this->connection = $connection; $this->memcacheConnection = $memcacheConnection; } 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->flush(); } } } 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
PS_CS4 Skrevet 29. desember 2008 Del Skrevet 29. desember 2008 (endret) La til flushing av memcache i deleteEntry. Hva skal det være godt for ? Endret 29. desember 2008 av PS_CS4 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å