Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Config
- {
- private $dbh;
- private $config;
- public function __construct(\PDO $dbh)
- {
- $this->dbh = $dbh;
- if(!apc_exists("config")) {
- $this->config = array();
- $query = $this->dbh->prepare("SELECT * FROM config");
- $query->execute();
- while($row = $query->fetch()) {
- $this->config[$row['setting']] = $row['value'];
- }
- apc_add("config", $this->config);
- }
- }
- public function __get($setting)
- {
- return $this->config[$setting];
- }
- public function __set($setting, $value)
- {
- $query = $this->dbh->prepare("UPDATE config SET value = ? WHERE setting = ?");
- if($query->execute(array($value, $setting))) {
- $this->config[$setting] = $value;
- if(apc_exists("config")) {
- apc_delete("config");
- }
- apc_add("config", $this->config);
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement