数据库驱动核心类
API - Module_Database_Driver
- Database_Driver::__construct
- Database_Driver::__destruct
- Database_Driver::compile - 构建SQL语句
- Database_Driver::query - 查询
- Database_Driver::connect - 连接数据库
- Database_Driver::close_connect - 关闭链接
- Database_Driver::escape - Sanitize a string by escaping characters that could cause an SQL
- Database_Driver::quote_table
- Database_Driver::quote - Quote a value for an SQL query.
- Database_Driver::connection - 获取当前连接
- Database_Driver::connection_id - 获取当前连接的唯一ID
- Database_Driver::transaction - 获取事务对象
- Database_Driver::last_query - 最后查询的SQL语句
构建SQL语句
查询
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$sql |
string |
查询语句 | |
$as_object |
string |
是否返回对象 | null |
$use_master |
boolean |
是否使用主数据库,不设置则自动判断 | null |
Database_Driver_MySQLI_Result
连接数据库
$use_connection_type 默认不传为自动判断,可传true/false,若传字符串(只支持a-z0-9的字符串),则可以切换到另外一个连接,比如传other,则可以连接到$this->_connection_other_id所对应的ID的连接
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$use_connection_type |
boolean |
是否使用主数据库 | null |
关闭链接
Sanitize a string by escaping characters that could cause an SQL injection attack.
$value = $db->escape('any string');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value to quote |
string
Quote a value for an SQL query.
$db->quote(null); // 'NULL' $db->quote(10); // 10 $db->quote('fred'); // 'fred'
Objects passed to this function will be converted to strings.
[Database_Expression] objects will use the value of the expression.
[Database_Query] objects will be compiled and converted to a sub-query.
All other objects will be converted using the __toString
method.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
mixed |
Any value to quote |
string
获取当前连接
mysqli
mysql
获取当前连接的唯一ID
string
获取事务对象
Database_Transaction
最后查询的SQL语句
string
获取一个随机HOST
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$exclude_hosts |
array |
排除的HOST | array(0) |
$type |
string |
配置类型 | null |
获取链接唯一hash
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$hostname |
string |
$hostname | |
$port |
int |
$port | |
$username |
string |
$username |
string
根据数据库连接唯一hash获取数据信息
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$hash |
string |
$has |
array
array('hostname'=>'','port'=>'','username'=>'')切换编码
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
$value |
设置连接类型
$use_connection_type 默认不传为自动判断,可传true/false,若传字符串(只支持a-z0-9的字符串),则可以切换到另外一个连接,比如传other,则可以连接到$this->_connection_other_id所对应的ID的连接
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$use_connection_type |
boolean|string |
$use_connection_type |