Properties

$table_name

$table_name : 

Type

$ci

$ci : 

Type

$prefix

$prefix : 

Type

$cache_dir

$cache_dir : 

Type

$primary_key

$primary_key : 

Type

$_parts

$_parts : 

Type

$dbname

$dbname : 

Type

$field_type

$field_type : 

Type

$table_field

$table_field : 

Type

$pri_column

$pri_column : 

Type

Methods

__construct()

__construct() : void

Class constructor

get_table_fields()

get_table_fields(  $is_news = false) : array

获取数据表字段信息

Parameters

$is_news

Returns

array —

数据表字段信息

get_field_type()

get_field_type(  $is_news = false) : array

获取数据表字段类型

Parameters

$is_news

Returns

array —

数据表字段类型

get_fields_type()

get_fields_type(  $table_name) 

获取字段类型

Parameters

$table_name

set_table_name()

set_table_name(string  $table_name) : $this

设置当前数据表的名称

Parameters

string $table_name

数据表名称

Returns

$this

set_primary_key()

set_primary_key(string  $primary_key) : $this

设置数据表主键

Parameters

string $primary_key

数据表主键

Returns

$this

from()

from(mixed  $table_name = null,   $fields = null) : $this

组装SQL语句中的FROM语句

用于处理 SELECT fields FROM table之类的SQL语句部分

Parameters

mixed $table_name

所要查询的数据表名,参数支持数组

$fields

Returns

$this

where()

where(string  $where, string  $value = null) : $this

组装SQL语句的WHERE语句

用于处理 WHERE id=3721 诸如此类的SQL语句部分

Parameters

string $where

WHERE的条件

string $value

数据参数,一般为字符或字符串

Returns

$this

orwhere()

orwhere(string  $where, string  $value = null) : $this

组装SQL语句的ORWHERE语句

用于处理 ORWHERE id=2011 诸如此类的SQL语句部分

Parameters

string $where

WHERE的条件

string $value

数据参数,一般为字符或字符串

Returns

$this

order()

order(mixed  $string) : $this

组装SQL语句排序(ORDER BY)语句

用于处理 ORDER BY post_id ASC 诸如之类的SQL语句部分

Parameters

mixed $string

排序条件。注:本参数支持数组

Returns

$this

limit()

limit(integer  $offset, integer  $count = null) : $this

组装SQL语句LIMIT语句

limit(10,20)用于处理LIMIT 10, 20之类的SQL语句部分

Parameters

integer $offset

启始id, 注:参数为整形

integer $count

显示的行数

Returns

$this

page_limit()

page_limit(integer  $page, integer  $count) : $this

组装SQL语句的LIMIT语句

注:本方法与$this->limit()功能相类,区别在于:本方法便于分页,参数不同

Parameters

integer $page

当前的页数

integer $count

每页显示的数据行数

Returns

$this

join()

join(string  $table_name, string  $where) : $this

组装SQL语句中LEFT JOIN语句

jion('表名2', '关系语句')相当于SQL语句中LEFT JOIN 表2 ON 关系SQL语句部分

Parameters

string $table_name

数据表名,注:本参数支持数组,主要用于数据表的alias别名

string $where

join条件,注:不支持数组

Returns

$this

group()

group(mixed  $group_name) : $this

组装SQL的GROUP BY语句

用于处理SQL语句中GROUP BY语句部分

Parameters

mixed $group_name

所要排序的字段对象

Returns

$this

having()

having(string|array  $where, string  $value = null) : $this

组装SQL的HAVING语句

用于处理 having id=2011 诸如此类的SQL语句部分

Parameters

string|array $where

条件语句

string $value

数据表某字段的数据值

Returns

$this

orhaving()

orhaving(string|array  $where, string  $value = null) : $this

组装SQL的ORHAVING语句

用于处理or having id=2011 诸如此类的SQL语句部分

Parameters

string|array $where

条件语句

string $value

数据表某字段的数据值

Returns

$this

quote_into()

quote_into(mixed  $value) : string|string

字符串转义函数

SQL语句指令安全过滤,用于字符转义

Parameters

mixed $value

所要转义的字符或字符串,注:参数支持数组

Returns

string|string

select()

select(boolean  $all_data = true,   $cache) : array

执行SQL语句中的SELECT查询语句

组装SQL语句并完成查询,并返回查询结果,返回结果可以是多行,也可以是单行

Parameters

boolean $all_data

是否输出为多行数据,默认为true,即多行数据;当false时输出的为单行数据

$cache

Returns

array

count()

count(  $table_name) 

Parameters

$table_name

select_all()

select_all(array  $fields = null, mixed  $order = null,   $order_asc = false, integer  $offset = true,   $page_no = 1,   $table_name = null) : array

查询数据表多行数据

根据一个查询条件,获取多行数据。并且支持数据排序

Parameters

array $fields

返回数据的数据表字段.默认为全部字段.注:本参数为数组

mixed $order

排序条件

$order_asc
integer $offset

limit启起ID

$page_no
$table_name

Returns

array

select_one()

select_one(  $value = null) : string

对数据表的主键查询

根据主键,获取某个主键的一行信息,主键可以类内设置。默认主键为数据表的物理主键 如果数据表没有主键,可以在model中定义

Parameters

$value

Returns

string —

所要查询数据信息(单行或多行)

getAll()

getAll(mixed  $where, \sring  $value = null, array  $fields = null, mixed  $order = null, integer  $offset = null, integer  $count = null) : array

查询数据表多行数据

根据一个查询条件,获取多行数据。并且支持数据排序

Parameters

mixed $where

查询条件

\sring $value

数值

array $fields

返回数据的数据表字段.默认为全部字段.注:本参数为数组

mixed $order

排序条件

integer $offset

limit启起ID

integer $count

显示的行数

Returns

array

insert()

insert(array  $data) : boolean

数据表写入操作

向当前model对应的数据表插入数据

Parameters

array $data

所要写入的数据内容。注:数据必须为数组

Returns

boolean

update()

update(array  $data, mixed  $where, string  $params = null) : boolean

数据表更改操作

更改当前model所对应的数据表的数据内容

Parameters

array $data

所要更改的数据内容

mixed $where

更改数据所要满足的条件

string $params

数值,对满足更改的条件的进一步补充

Returns

boolean

delete_one()

delete_one(  $value = null) 

Parameters

$value

delete()

delete(  $where,   $value = null) 

数据表删除操作

Parameters

$where
$value

execute()

execute(  $sql,   $all_data = true,   $cache) 

执行SQL查询语句 $all_rows 是否显示全部数据开关,当为true时,显示全部数据,为false时,显示一行数据,默认为true $cache 缓存时间,单位秒。

Parameters

$sql
$all_data
$cache

query()

query(  $sql) 

执行SQL语句操作

Parameters

$sql

get_insert_id()

get_insert_id() 

获取insert_id操作

load_model()

load_model(  $model_name) 

实例化model

Parameters

$model_name

is_table_exists()

is_table_exists(  $table) 

检查表是否存在

Parameters

$table

get_tables()

get_tables() 

当前数据库中的所有表

get_server_info()

get_server_info() 

获取mysql数据库服务器信息

num_fields()

num_fields(  $sql) 

字段的数量

Parameters

$sql

num_rows()

num_rows(  $sql) 

结果集中的数量

Parameters

$sql

__set()

__set(  $name,   $value) 

自动变量设置

Parameters

$name
$value

__toString()

__toString() 

输出类的实例化对象

_gl()

_gl(  $str) 

Parameters

$str

page_init()

page_init(  $data) 

分页初始化 返回page对象

Parameters

$data

pages()

pages(  $total_rows) 

Parameters

$total_rows

emoji_encode()

emoji_encode(  $str) 

Parameters

$str

emoji_decode()

emoji_decode(  $str) 

Parameters

$str

user_nickname_decode()

user_nickname_decode(  $array) 

Parameters

$array

__get()

__get(string  $key) 

__get magic

Allows models to access CI's loaded classes using the same syntax as controllers.

Parameters

string $key

get_model_id()

get_model_id() 

get_controller_id()

get_controller_id() 

get_table_name()

get_table_name() : string

获取当前model所对应的数据表的名称

注:若数据表有前缀($prefix)时,将自动加上数据表前缀。

Returns

string —

数据表名

get_table_info()

get_table_info() : array

获取数据表字段信息

主键及所有字段信息,返回数据类型为数组

Returns

array —

字段信息

get_primary_key()

get_primary_key() : string

获取数据表主键

Returns

string —

数据表主键

create_cache()

create_cache() : boolean

创建当前model的缓存文件

用于创建当前model的缓存文件,用于减轻数据反复查询数据表字段信息的操作,从而提高程序的运行效率

Returns

boolean

load_cache()

load_cache() : array

加载当前model的缓存文件内容

Returns

array —

缓存文件内容

clear_cache()

clear_cache() : boolean

清空当前model的缓存文件

Returns

boolean

parse_cache_file()

parse_cache_file() : string

分析当前model缓存文件的路径

Returns

string —

缓存文件的路径

_parse_fields()

_parse_fields(array  $fields = null) : string

分析数据表字段信息

Parameters

array $fields

数据表字段信息.本参数为数组

Returns

string

_where()

_where(string  $where, string  $value = null, boolean  $is_where = true) : $this

组装SQL语句中WHERE及ORWHERE语句

本方法用来为方法where()及orwhere()提供"配件"

Parameters

string $where

SQL中的WHERE语句中的条件.

string $value

数值(数据表某字段所对应的数据,通常都为字符串或字符)

boolean $is_where

注:为true时是为where(), 反之 为orwhere()

Returns

$this

_having()

_having(mixed  $where, string  $value = null, boolean  $is_having = true) : $this

组装SQL的HAVING,ORHAVING语句

为having()及orhaving()方法的执行提供'配件'

Parameters

mixed $where

条件语句

string $value

数据表某字段的数据值

boolean $is_having

当参数为true时,处理having(),当为false时,则为orhaving()

Returns

$this