DB 配置
在使用 DB 相关函数的时候,需要配置数据库相关信息。一般存放在文件中。
新建配置文件 conf.php:
<?php
return array (
"cache" => array (
"enable" => true,
"type" => "xcache",
"memcached" => array (
"host" => "localhost",
"port" => "11211",
"cachepre" => "bbs_",
),
"redis" => array (
"host" => "localhost",
"port" => "6379",
"cachepre" => "bbs_",
),
"xcache" => array (
"cachepre" => "bbs_",
),
"yac" => array (
"cachepre" => "bbs_",
),
"apc" => array (
"cachepre" => "bbs_",
),
"mysql" => array (
"cachepre" => "bbs_",
),
),
);
?>
如果用 MySQL 来存储数据,得自己建立表:
# 缓存表,用来保存临时数据。
DROP TABLE IF EXISTS bbs_cache;
CREATE TABLE bbs_cache (
k char(32) NOT NULL default "",
v mediumtext NOT NULL,
expiry int(11) unsigned NOT NULL default "0", # 过期时间
PRIMARY KEY(k)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
include 配置文件:
<?php
$conf = include "./conf.php";
include "./xiunophp/xiunophp.php";
// 下面就可以使用 cache_xxx() 系列函数了,具体请参看文档。
cache_set("key1", "value1");
cache_get("key1");
?>