Advertisement
cuonic

Untitled

Aug 27th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2.  
  3. class Config
  4. {
  5.     private $dbh;
  6.     private $config;
  7.  
  8.     public function __construct(\PDO $dbh)
  9.     {
  10.         $this->dbh = $dbh;
  11.  
  12.         if(!apc_exists("config")) {
  13.             $this->config = array();
  14.  
  15.             $query = $this->dbh->prepare("SELECT * FROM config");
  16.             $query->execute();
  17.  
  18.             while($row = $query->fetch()) {
  19.                 $this->config[$row['setting']] = $row['value'];
  20.             }
  21.  
  22.             apc_add("config", $this->config);
  23.         }
  24.     }
  25.  
  26.     public function __get($setting)
  27.     {
  28.         return $this->config[$setting];
  29.     }
  30.  
  31.     public function __set($setting, $value)
  32.     {
  33.         $query = $this->dbh->prepare("UPDATE config SET value = ? WHERE setting = ?");
  34.  
  35.         if($query->execute(array($value, $setting))) {
  36.             $this->config[$setting] = $value;
  37.  
  38.             if(apc_exists("config")) {
  39.                 apc_delete("config");
  40.             }
  41.  
  42.             apc_add("config", $this->config);
  43.            
  44.             return true;
  45.         } else {
  46.             return false;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement