Exemplo n.º 1
0
 /**
  * Initialize MySQL caching: connect to the database and create the cache table if needed.
  * @return When initialization succeeds, true; otherwise, false.
  */
 private static function initMySql()
 {
     if (self::$mysqlTableExists === null) {
         clAPI::trace('Initializing MySQL cache.');
         if (!(self::$mysqlConnection = mysql_connect(self::$options['mysql_host'], self::$options['mysql_username'], self::$options['mysql_password']))) {
             clAPI::error('Failed to connect to the MySQL server.');
             return false;
         }
         if (!@mysql_select_db(self::$options['mysql_database'], self::$mysqlConnection)) {
             clAPI::error('Unable to select database `' . self::$options['mysql_database'] . '`');
             return false;
         }
         if (!self::$options['nocreate']) {
             self::$mysqlTableExists = self::cacheTableName() == self::getVar("SHOW TABLES LIKE '" . self::cacheTableName() . "'");
             if (!self::$mysqlTableExists) {
                 clAPI::trace('Creating cache table <b>' . self::cacheTableName() . '</b>');
                 if (!@mysql_query('CREATE TABLE `' . self::cacheTableName() . '` (`id` VARCHAR(32) NOT NULL PRIMARY KEY, `cached_on` DATETIME NOT NULL, `content` LONGBLOB)', self::$mysqlConnection)) {
                     clAPI::error('Failed to create cache table `' . self::cacheTableName() . '`: ' . mysql_error(self::$mysqlConnection));
                     return false;
                 } else {
                     self::$mysqlTableExists = true;
                 }
             } else {
                 return true;
             }
         } else {
             self::$mysqlTableExists = true;
             clAPI::warn("You didn't let coreylib check to see if the cache table was there.  Hope you're right.");
             return true;
         }
     } else {
         return self::$mysqlTableExists;
     }
 }