OpenSencillo  2015.002
mysql.php File Reference

Go to the source code of this file.

Functions

 quickcache_db_connect ()
 quickcache_db_disconnect ()
 quickcache_db_query ($query)
 quickcache_restore ()
 quickcache_write ($gzdata, $datasize, $datacrc)
 quickcache_do_gc ()
 quickcache_do_start ()
 quickcache_do_end ()

Function Documentation

Definition at line 22 of file mysql.php.

                                 {
  $GLOBALS["sql_link"] = @mysql_connect($GLOBALS["QUICKCACHE_DB_HOST"],
                                        $GLOBALS["QUICKCACHE_DB_USERNAME"],
                                        $GLOBALS["QUICKCACHE_DB_PASSWORD"]);
}

Definition at line 31 of file mysql.php.

                                    {
  mysql_close($GLOBALS["sql_link"]);
}
quickcache_db_query ( query)

Definition at line 38 of file mysql.php.

                                     {
  // quickcache_debug("Executing SQL-query $query");
  $ret = @mysql_db_query($GLOBALS["QUICKCACHE_DB_DATABASE"],
                         $query,
                         $GLOBALS["sql_link"]);
  return $ret;
}

Definition at line 151 of file mysql.php.

                             {
  // Disconnect from db
  quickcache_db_disconnect();
}

Definition at line 124 of file mysql.php.

                            {
  quickcache_db_query("delete from ".
                      $GLOBALS["QUICKCACHE_DB_TABLE"].
                   " where CACHEEXPIRATION<=".
                      time().
                   " and CACHEEXPIRATION!=0"
                  );

  // Are we allowed to do an optimize table-call?
  // As noted, first check if this works on your mysql-installation!
  if ($GLOBALS["QUICKCACHE_OPTIMIZE"]) {
      quickcache_db_query("OPTIMIZE TABLE ".$GLOBALS["QUICKCACHE_DB_TABLE"]);
  }
}

Definition at line 142 of file mysql.php.

                               {
  // Connect to db
  quickcache_db_connect();
}

Definition at line 49 of file mysql.php.

                              {
  $res = quickcache_db_query("select GZDATA, DATASIZE, DATACRC from ".
                              $GLOBALS["QUICKCACHE_DB_TABLE"].
                          " where CACHEKEY='".
                              addslashes($GLOBALS["quickcache_key"]).
                          "' and (CACHEEXPIRATION>".
                              time().
                          " or CACHEEXPIRATION=0)"
                         );

  if ($res && mysql_num_rows($res))
  {
    if ($row = mysql_fetch_array($res))
    {
      // restore data into global scope from found row
      $GLOBALS["quickcachedata_gzdata"]   = $row["GZDATA"];
      $GLOBALS["quickcachedata_datasize"] = $row["DATASIZE"];
      $GLOBALS["quickcachedata_datacrc"]  = $row["DATACRC"];
      return true;
    }
  }
  return false;
}
quickcache_write ( gzdata,
datasize,
datacrc 
)

Definition at line 76 of file mysql.php.

                                                        {
  $dbtable = $GLOBALS["QUICKCACHE_DB_TABLE"];

  // XXX: Later on, maybe implement locking mechanism inhere.

  // Check if it already exists
  $res = quickcache_db_query("select CACHEEXPIRATION from $dbtable".
                          " where CACHEKEY='".
                              addslashes($GLOBALS["quickcache_key"]).
                          "'"
                         );


  if (!$res || mysql_num_rows($res) < 1) {
    // Key not found, so insert
    $res = quickcache_db_query("insert into $dbtable".
                            " (CACHEKEY, CACHEEXPIRATION, GZDATA,".
                            " DATASIZE, DATACRC) values ('".
                                addslashes($GLOBALS["quickcache_key"]).
                            "',".
                                (($GLOBALS["QUICKCACHE_TIME"] != 0) ?
                                (time()+$GLOBALS["QUICKCACHE_TIME"]) : 0).
                            ",'".
                                addslashes($gzdata).
                            "', $datasize, $datacrc)"
                           );
    // This fails with unique-key violation when another thread has just
    // inserted the same key. Just continue, as the result is (almost)
    // the same.
  } else {
    // Key found, so update
    $res = quickcache_db_query("update $dbtable set CACHEEXPIRATION=".
                                (($GLOBALS["QUICKCACHE_TIME"] != 0) ?
                                (time()+$GLOBALS["QUICKCACHE_TIME"]) : 0).
                            ", GZDATA='".
                                addslashes($gzdata).
                            "', DATASIZE=$datasize, DATACRC=$datacrc where".
                            " CACHEKEY='".
                                addslashes($GLOBALS["quickcache_key"]).
                            "'"
                           );
    // This might be an update too much, but it shouldn't matter
  }
}
 All Data Structures Files Functions Variables