常用表说明

ims_mc_mapping_fans 粉丝表
ims_mc_members 会员表

数据库操作函数

表名 
tablename('mc_members')
查询一条数据
pdo_get('yoby_demo',['id'=>1]);
["company like"=>"%$kw%"];['id >='=>12];["n +="=>1];['id'=>[1,2,3]]in替代
pdo_get('users', array(), array('COUNT(*)', 'uid', 'MAX(uid)', 'MIN(uid) AS minuid'));
pdo_get('yoby_demo',['id'=>1],['title','num']);返回特定字段
pdo_get('yoby_demo',[],['count(*) as z','title','num','max(num)']);
pdo_fetch("SELECT username, uid FROM ".tablename('users')." WHERE uid = :uid LIMIT 1", array(':uid' => 1));
查询单字段
pdo_getcolumn('yoby_demo',['id'=>1],'title');
pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('users'));
查询多条记录
表名,条件,返回字段,主键,排序,限制条数
pdo_getall('yoby_demo',[],[],'','id desc','.($pindex-1)* $psize.','.$psize); 
pdo_fetchall("SELECT username, uid FROM ".tablename('users'), []);
插入数据,第二个参数数组
pdo_insert('yoby_demo',[]);
$id = pdo_insertid();插入id
修改
pdo_update('yoby_demo',['num +='=>1],['id'=>1]);
删除
pdo_delete('yoby_demo',['id'=>1]);
pdo_delete($this->table_reply, "id IN ('".implode("','", $deleteid)."')");
执行sql
pdo_query("DELETE FROM ".tablename('users')." WHERE uid = :uid", array(':uid' => 2));
支持多条sql用分号隔开
pdo_run($sql);
显示调试语句
pdo_debug();
检测某个字段是否存在
pdo_fieldexists('shopping_goods', 'credit');
检测某个表是否存在
pdo_tableexists($tablename)
检测表是否为空
pdo_exists($tb)
获取数据条数
pdo_count($tb,['id'=>1])
事务处理
 try {
            pdo_begin();// 开启事务
            $rs = pdo_get("yoby_xy_shop",["id"=>$id,"isdui"=>1,"status"=>1]);//兑换商品
            if(!$rs){
                throw new Exception("查询出错", 1);
            }
           if(!pdo_update("yoby_xy_shop",['n -='=>1],['id'=>$id])){
               throw new Exception("库存减少失败", 2);
           }
            pdo_commit();//提交事务
            json(200,"兑换成功");
        } catch (Exception $e) {
            pdo_rollback();//回滚事务
            json(400,$e->getMessage());
        }
文档更新时间: 2022-06-15 12:26   作者:Yoby