ODBC¶
ODBC模式MSSQL数据库模型类
属性 | 值 |
---|---|
命名空间 | fize\db\realization\mssql\mode |
类名 | Odbc |
父类 | fize\db\realization\mssql\Db |
方法: |
---|
方法名 | 说明 |
---|---|
__construct() | 构造 |
__destruct() | 析构时释放ODBC资源 |
query() | 执行一个SQL语句并返回相应结果 |
lastInsertId() | 返回最后插入行的ID或序列值 |
newFeature() | |
top() | 设置TOP,支持链式调用 |
limit() | 模拟MySQL的LIMIT语句,支持链式调用 |
crossJoin() | CROSS JOIN条件,支持链式调用 |
fullJoin() | FULL JOIN条件,支持链式调用 |
leftOuterJoin() | LEFT OUTER JOIN条件,支持链式调用 |
rightOuterJoin() | RIGHT OUTER JOIN条件,支持链式调用 |
select() | 执行查询,返回结果记录列表 |
paginate() | 完整分页,执行该方法可以获取到分页记录、完整记录数、总页数,可用于分页输出 |
prototype() | 返回当前使用的数据库对象原型,用于原生操作 |
startTrans() | 开始事务 |
commit() | 执行事务 |
rollback() | 回滚事务 |
getLastSql() | 获取最后组装的SQL |
distinct() | 指定distinct查询 |
field() | 指定要查询的字段,支持链式调用 |
prefix() | 设置表前缀 |
table() | 指定当前要操作的表 |
alias() | 对当前表设置别名 |
group() | GROUP语句 |
order() | 设置排序条件 |
where() | 设置WHERE语句 |
having() | HAVING语句 |
join() | JOIN条件,可以使用所有JOIN变种 |
innerJoin() | INNER JOIN条件 |
leftJoin() | LEFT JOIN条件 |
rightJoin() | RIGHT JOIN条件 |
union() | UNION语句 |
unionAll() | UNION ALL语句 |
unionDistinct() | UNION DISTINCT语句 |
insert() | 插入记录 |
insertGetId() | 插入记录,并返回最后插入行的ID或序列值 |
fetch() | 遍历当前结果集 |
delete() | 删除记录 |
update() | 更新记录 |
findOrNull() | 执行查询,获取单条记录 |
find() | 执行查询,获取单条记录,如果未找到则抛出错误 |
value() | 得到某个字段的值 |
column() | 得到某个列的数组 |
page() | 使用模拟的LIMIT语句进行简易分页,支持链式调用 |
count() | COUNT查询 |
sum() | SUM查询 |
min() | MIN查询 |
max() | MAX查询 |
avg() | AVG查询 |
setValue() | 设置数据 |
setInc() | 字段值增长 |
setDec() | 字段值减少 |
insertAll() | 批量插入记录 |
方法¶
__construct()¶
构造
public function __construct (
string $host,
string $user,
string $pwd,
string $dbname,
mixed $port = "",
string $driver = null
)
参数: |
|
---|
query()¶
执行一个SQL语句并返回相应结果
public function query (
string $sql,
array $params = [],
callable $callback = null
) : array|int
参数: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
返回值: | SELECT语句返回数组,其余返回受影响行数。 |
lastInsertId()¶
返回最后插入行的ID或序列值
public function lastInsertId (
string $name = null
) : int|string
参数: |
|
---|
limit()¶
模拟MySQL的LIMIT语句,支持链式调用
public function limit (
int $rows,
int $offset = null
) : $this
参数: |
|
---|
crossJoin()¶
CROSS JOIN条件,支持链式调用
public function crossJoin (
string $table,
string $on = null
) : $this
参数: |
|
---|
fullJoin()¶
FULL JOIN条件,支持链式调用
public function fullJoin (
string $table,
string $on = null
) : $this
参数: |
|
---|
leftOuterJoin()¶
LEFT OUTER JOIN条件,支持链式调用
public function leftOuterJoin (
string $table,
string $on = null
) : $this
参数: |
|
---|
rightOuterJoin()¶
RIGHT OUTER JOIN条件,支持链式调用
public function rightOuterJoin (
string $table,
string $on = null
) : $this
参数: |
|
---|
select()¶
执行查询,返回结果记录列表
public function select (
bool $cache = true
) : array
参数: |
|
---|
paginate()¶
完整分页,执行该方法可以获取到分页记录、完整记录数、总页数,可用于分页输出
public function paginate (
int $page,
int $size = 10
) : array
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 数组键名为count、pages、rows |
针对MSSQL的再处理,删除非必要的中间字段
getLastSql()¶
获取最后组装的SQL
public function getLastSql (
bool $real = false
) : string
参数: |
|
---|
仅供日志使用的SQL语句,由于本身存在SQL危险请不要真正用于执行
distinct()¶
指定distinct查询
public function distinct (
bool $distinct = true
) : $this
参数: |
|
---|
field()¶
指定要查询的字段,支持链式调用
public function field (
array|string $fields
) : $this
参数: |
|
---|
table()¶
指定当前要操作的表
public function table (
string $name,
string $prefix = null
) : $this
参数: |
|
---|
order()¶
设置排序条件
public function order (
array|string $field_order
) : $this
参数: |
|
---|
where()¶
设置WHERE语句
public function where (
\Query|array|string $statements,
array $parse = []
) : $this
参数: |
|
---|
通常情况下,我们使用简洁方式来更简便地定义条件,对于复杂条件无法满足的,可以使用查询器或者直接使用预处理语句
having()¶
HAVING语句
public function having (
\Query|array|string $statements,
array $parse = []
) : $this
参数: |
|
---|
通常情况下,我们使用简洁方式来更简便地定义条件,对于复杂条件无法满足的,可以使用查询器或者直接使用预处理语句
join()¶
JOIN条件,可以使用所有JOIN变种
public function join (
string|array $table,
string $type = "JOIN",
string $on = null,
string $using = null
) : $this
参数: |
|
---|
innerJoin()¶
INNER JOIN条件
public function innerJoin (
string|array $table,
string $on = null
) : $this
参数: |
|
---|
leftJoin()¶
LEFT JOIN条件
public function leftJoin (
string|array $table,
string $on = null
) : $this
参数: |
|
---|
rightJoin()¶
RIGHT JOIN条件
public function rightJoin (
string|array $table,
string $on = null
) : $this
参数: |
|
---|
union()¶
UNION语句
public function union (
string $sql,
string $union_type = "UNION"
) : $this
参数: |
|
---|
unionAll()¶
UNION ALL语句
public function unionAll (
string $sql
) : $this
参数: |
|
---|
unionDistinct()¶
UNION DISTINCT语句
public function unionDistinct (
string $sql
) : $this
参数: |
|
---|
insertGetId()¶
插入记录,并返回最后插入行的ID或序列值
public function insertGetId (
array $data,
string $name = null
) : int|string
参数: |
|
---|
fetch()¶
遍历当前结果集
public function fetch (
callable $func
)
参数: |
|
---|
由于少了一层循环和转化,fetch方法比select性能上略有提升,但不方便外部调用,特别是MVC等架构
findOrNull()¶
执行查询,获取单条记录
public function findOrNull (
bool $cache = false
) : array
参数: |
|
||||
---|---|---|---|---|---|
返回值: | 如果无记录则返回null |
find()¶
执行查询,获取单条记录,如果未找到则抛出错误
public function find (
bool $cache = false
) : array
参数: |
|
---|
value()¶
得到某个字段的值
public function value (
string $field,
mixed $default = null,
bool $force = false
) : mixed
参数: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
返回值: | 如果$force为true时则返回数字类型 |
page()¶
使用模拟的LIMIT语句进行简易分页,支持链式调用
public function page (
int $index,
int $prepg = 10
) : $this
参数: |
|
---|
min()¶
MIN查询
public function min (
string $field,
bool $force = true
) : mixed
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 如果$force为true时真返回数字类型 |
max()¶
MAX查询
public function max (
string $field,
bool $force = true
) : mixed
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 如果$force为true时真返回数字类型 |
setValue()¶
设置数据
public function setValue (
mixed $field,
mixed $value
) : int
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 返回受影响记录条数 |
setInc()¶
字段值增长
public function setInc (
string $field,
int $step = 1
) : int
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 返回受影响记录条数 |
setDec()¶
字段值减少
public function setDec (
string $field,
int $step = 1
) : int
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 返回受影响记录条数 |
insertAll()¶
批量插入记录
public function insertAll (
array $data_sets,
array $fields = null
) : int
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 返回插入成功的记录数 |