本文整理汇总了PHP中phpFastCache::autosize方法的典型用法代码示例。如果您正苦于以下问题:PHP phpFastCache::autosize方法的具体用法?PHP phpFastCache::autosize怎么用?PHP phpFastCache::autosize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpFastCache
的用法示例。
在下文中一共展示了phpFastCache::autosize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: selectDB
private static function selectDB($object)
{
$res = array('db' => "", 'item' => "");
if (is_array($object)) {
$key = array_keys($object);
$key = $key[0];
$res['db'] = $key;
$res['item'] = self::safename($object[$key]);
} else {
$res['item'] = self::safename($object);
}
if ($res['db'] == "" && self::$sys['method'] == "files") {
$res['db'] = "files";
}
// for auto database
if ($res['db'] == "" && self::$storage == "mpdo") {
$create_table = false;
if (!file_exists('sqlite:' . self::getPath() . '/phpfastcache.c')) {
$create_table = true;
}
if (self::$autodb == "") {
try {
self::$autodb = new PDO('sqlite:' . self::getPath() . '/phpfastcache.c');
self::$autodb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOexception $e) {
die("Please CHMOD 0777 or Writable Permission for " . self::getPath());
}
}
if ($create_table == true) {
self::$autodb->exec('CREATE TABLE IF NOT EXISTS "main"."db" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "item" VARCHAR NOT NULL UNIQUE , "dbname" INTEGER NOT NULL )');
}
$db = self::$autodb->prepare("SELECT * FROM `db` WHERE `item`=:item");
$db->execute(array(":item" => $res['item']));
$row = $db->fetch(PDO::FETCH_ASSOC);
if (isset($row['dbname'])) {
// found key
$res['db'] = $row['dbname'];
} else {
// not key // check filesize
if ((int) self::$autosize < 10) {
self::$autosize = 10;
}
// get last key
$db = self::$autodb->prepare("SELECT * FROM `db` ORDER BY `id` DESC");
$db->execute();
$row = $db->fetch(PDO::FETCH_ASSOC);
$dbname = isset($row['dbname']) ? $row['dbname'] : 1;
$fsize = file_exists(self::getPath() . "/" . $dbname . ".cache") ? filesize(self::getPath() . "/" . $dbname . ".cache") : 0;
if ($fsize > 1024 * 1024 * (int) self::$autosize) {
$dbname = (int) $dbname + 1;
}
try {
$insert = self::$autodb->prepare("INSERT INTO `db` (`item`,`dbname`) VALUES(:item,:dbname)");
$insert->execute(array(":item" => $res['item'], ":dbname" => $dbname));
} catch (PDOexception $e) {
die('Database Error - Check A look at self::$autodb->prepare("INSERT INTO ');
}
$res['db'] = $dbname;
}
}
return $res;
}