天天看点

phpcms自定义函数

公共函数存放地址

\www\phpcms\libs\functions\extention.func.php

<?php

 function tests(){

     $db = pc_base::load_model('content_model');

    if(!strpos($db->table_name,'picture')){

    $db->table_name = $db->table_name.'picture';

    }

    //数据库名称  picture

    $res = $db->get_one(array('id'=>intval(1)));

    //获取单条数据

    $catid=intval($res['catid'])+1;

    $db->update(array('catid'=>$catid),array('id'=>1));

    //更新数据   第一个数组更新内容   第二个数组更新条件

    var_dump($res);

 }

?>

前台调用

{tests()}

phpcms自定义函数

1、查询

  $this->select($where = '', $data = '*', $limit = '', $order = '', $group = '', $key='')   返回结果集数组

         条件 ,字段(id,name,email....),范围   排序方式,分组方式,按建名排序

2、查询多条数据并分页

    listinfo($where = '', $order = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array())

3、获取单条记录查询

      get_one($where = '', $data = '*', $order = '', $group = '')

4、直接执行sql查询

    query($sql);

5、获取最后一次添加记录的主键号  insert_id()

6、执行更新记录操作   update($data, $where = '')  $data 建议为数组,$where 可为数组可为字符串

7、执行删除记录操作   delete($where)

8、计算记录数         count($where = '')

9、获取最后数据库操作影响到的条数  affected_rows()

10、获取数据表主键     get_primary()

11、获取表字段     get_fields($table_name = '')

12、检查表是否存在   table_exists($table)

13、 检查字段是否存在  field_exists($field)