伊迩主题 YieerTheme

不一样的zblog主题模板!

创建新表创建表类的方法

摘要:在主题或者插件的include.php文件顶部引用文件 PHPinclude_once _

在主题或者插件的include.php文件顶部引用文件

 PHP
include_once __DIR__.'/database/index.php';

在引入的php里面写入创建表类的代码

 PHP
$ytecn_database = array(
    'ytecn_table'   => array(
        'name'           => '%pre%ytecn_table',
        'info'           => array(
            'ID'           => array('ytecn_ID','integer','',0),
            'Name'        => array('ytecn_Name','string',255,''),
            'Content'        => array('ytecn_Content', 'string', '', '')
            'Status'      => array('ytecn_Status','integer','',0),
        ),
    ),);foreach ($ytecn_database as $k => $v) {
    $table[$k] = $v['name'];
    $datainfo[$k] = $v['info'];}function ytecn_table_CreateTable() {
    global $zbp, $ytecn_database;
    foreach ($ytecn_database as $k => $v) {
        if (!$zbp->db->ExistTable($v['name'])) {
            $s = $zbp->db->sql->CreateTable($v['name'],$v['info']);
            $zbp->db->QueryMulit($s);
        }
    }}class ytecntable extends Base {
    public function __construct() {
        global $zbp;
        parent::__construct($zbp->table['ytecn_table'], $zbp->datainfo['ytecn_table'], __CLASS__);
    }
    public function __get($name)
    {
        global $zbp;
        switch ($name) {
            case 'Url':
                return "详情的url访问地址";
                break;
            default:
                return parent::__get($name);
                break;
        }
    }
    public static function GetList($select = null, $w = null, $order = null, $limit = null, $option = null) {
        global $zbp;
        if (empty($select)) {
            $select = array('*');
        }
        if (empty($w)) {
            $w = array();
        }
        $sql = $zbp->db->sql->Select(
            $zbp->table['ytecn_database'],
            $select,
            $w,
            $order,
            $limit,
            $option
        );
        $result = $zbp->GetListType('ytecntable', $sql);
        return $result;
    }}

在启动主题或者插件的时候执行创建表的函数

 PHP
function InstallPlugin_****() {
    ytecn_table_CreateTable();}

调用表列表

 PHP
$where = array();$where[] = array('=', 'ytecn_Status', 0);$array= ytecntable::GetList(null, $where, array("ytecn_ID" => "DESC"));foreach ($arrayas $item) {
    echo $item->Name;}

添加数据

 PHP
$table= new ytecntable;$table->Name = '豫唐';$table->Status= 0;$table->Save();

修改数据

 PHP
$id = (int)GetVars("id", "POST");$table= new ytecntable;$table->LoadInfoByID($id);$table->Name = '豫唐ytecn';$table->Status= 1;$table->Save();

删除数据

 PHP
$id = GetVars("id", "GET");$table= new ytecntable;if (!empty($id)) {
    $table->LoadInfoByID((int) $id);}$table->Del();


建站!你有充足的理由选择我们

Z-BlogPHP是一款开源免费、小巧强大的博客程序与CMS建站系统
QQ客服 微信客服微信客服 主题模板 手机访问手机访问