zblog
当前位置:首页 > 商学院 > zblog > 正文内容

zblog

zblog创建新表创建表类的方法

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

在主题或者插件的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;
$w=array();
$w['Pid']=$pid;
$w['Uid']=$zbp->user->ID;
$w['Type']=$type;
$table->LoadInfoByFields($w);
print_r($table);

查询单条数据(通过ID)

$table= new ytecntable;
$table->LoadInfoByID($id);
print_r($table);

添加数据

$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

分享给朋友:

相关文章

phpQuery获取HTML图片

phpQuery获取HTML图片

phpQuery获取HTML图片/**  * 获取html文本里的img  * @param string $content ...

zblogphp文章页面编辑页开始接口说明

zblogphp文章页面编辑页开始接口说明

接口名称:Filter_Plugin_Edit_Begin接口描述:文章编辑页加载前处理内容。应用场景:可直接跳转到其他页面,处理自身业务流程。调用方法:Add_Filter_Plugin('...

zblogphp1.5.2开发者迁移指南

zblogphp1.5.2开发者迁移指南

自此版本开始,加强安全相关功能。登录相关此版本不再使用 password Cookie,用户密码不再直接暴露。增加token Cookie,并且强制置于 httpOnly 模式。因此:1. 不再允许前...

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

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

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

zblog商业授权

zblog商业授权

        zblog的商用链接,已与2022年01月28从官网移除,git开源协议MIT。如你依然不放心,可以找豫...

GetList获取的文章怎么过滤某个分类

GetList获取的文章怎么过滤某个分类

通过 GetList 可以获取自定义的文章列表,他可以通过分类、作者、时间、标签、搜索、置顶、随机等等手段自由组合出你要的文章列表。过滤某个分类的代码如下(为了更加方便使用,我把实例做了下拆分处理)。...