Z-Blog
当前位置:首页 > 商学院 > Z-Blog > 正文内容

Z-Blog

创建新表创建表类的方法

豫唐网络2023-09-02 15:29582

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

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

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

$ytecn_database = array(
    'ytecn_table'   => array(
        'name'           => '%pre%ytecn_table',
        'info'           => array(
            'ID'           => array('ytecn_ID','integer','',0),
            'UID'        => array('ytecn_UID','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;
            case 'Author':
                return $zbp->GetMemberByID($this->UID);
            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;
    }
}

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

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

调用表列表

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

添加数据

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

修改数据

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

删除数据

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


完整源码案例:

请开通vip查阅

扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/331.html

分享给朋友:

相关文章

zblogphp文章提交的核心接口说明

zblogphp文章提交的核心接口说明

接口名称:Filter_Plugin_PostArticle_Core接口描述:接管本插件接口,将提交文章数据时,在过滤数据内容及保存数据前运行插件自定义代码,即可通过该接口更改保存的文章内容。应用场...

zblogphp程序报错后如何获得帮助

zblogphp程序报错后如何获得帮助

zblogphp程序报错后获取帮助分为免费和付费两种。免费帮助方法1开启调试模式(点击打开新链接),将截图发到群内。方法2提交工单或私信把网站信息发群主,等凑够一定数量后,群主开直播查错。付费帮助找群...

zba文件怎么使用?zba文件是什么?

zba文件怎么使用?zba文件是什么?

        .zba是zblogphp的专用应用格式。应用格式又分主题和插件两种。   ...

zblog提示授权文件非法怎么办

zblog提示授权文件非法怎么办

        zblog在开启主题或者插件的时候,有时候会提示授权文件非法。这种需要怎么处理么?  ...

zblog登录地址zblog后台登陆地址是多少

zblog登录地址zblog后台登陆地址是多少

zblog后台默认登陆地址:域名/zb_system/login.php安装有用户中心或者其他插件的会导致后台登录地址发生变化。开启《用户中心(百搭)》后,前台会员伪静态情况下默认登录地址《域名/Us...

zblog调用当前大分类下的其他小分类名称

zblog调用当前大分类下的其他小分类名称

文章页调用当前大分类下的其他小分类名称子分类内容{$cid=$article->Category->RootID?$article->Category->RootID:$art...