phpcms v9 数据库操作函数
建立相应表的数据模型:
如,表v9_yp_bproductcate
建立文件yp_bproductcate_model.class.php
<?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_sys_class('model', '', 0); class yp_bproductcate_model extends model { public function __construct() { $this->db_config = pc_base::load_config('database'); $this->db_setting = 'default'; $this->table_name = 'yp_bproductcate'; parent::__construct(); } } ?>
数据库操作示例如下:
<?php /** * 黄页企业与分类关系库操作类 */ defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_sys_class('model', '', 0); class yp_bproductcate_model extends model { public function __construct() { $this->db_config = pc_base::load_config('database'); $this->db_setting = 'default'; $this->table_name = 'yp_bproductcate'; parent::__construct(); } } ?>
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)
 
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号