Ejemplo n.º 1
0
 public function __construct($dsn, $name, $extension)
 {
     $this->options = array('user' => null, 'password' => null, 'prefix' => '');
     $this->options = array_merge($this->options, SimplePie_Cache::parse_DSN($dsn));
     try {
         $this->mysql = new PDO($dsn, $this->options['user'], $this->options['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
     } catch (PDOException $e) {
         $this->mysql = null;
         return;
     }
     $this->id = $name . $extension;
     if (!($query = $this->mysql->query('SHOW TABLES'))) {
         $this->mysql = null;
         return;
     }
     $db = array();
     while ($row = $query->fetchColumn()) {
         $db[] = $row;
     }
     if (!in_array($this->options['prefix'] . 'cache_data', $db)) {
         $query = $this->mysql->exec('CREATE TABLE `' . $this->options['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
         if ($query === false) {
             $this->mysql = null;
         }
     }
     if (!in_array($this->options['prefix'] . 'items', $db)) {
         $query = $this->mysql->exec('CREATE TABLE `' . $this->options['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
         if ($query === false) {
             $this->mysql = null;
         }
     }
 }