数据库MySQLI返回类
API - Driver_Database_Driver_MySQLI
- Database_Driver_MySQLI::connect - 连接数据库
- Database_Driver_MySQLI::connection - 获取当前连接
- Database_Driver_MySQLI::close_connect - 关闭链接
- Database_Driver_MySQLI::compile - 构建SQL语句
- Database_Driver_MySQLI::set_charset - 设置编码
- Database_Driver_MySQLI::escape - Sanitize a string by escaping characters that could cause an SQL
- Database_Driver_MySQLI::query - 查询
- Database_Driver_MySQLI::quote - Quote a value for an SQL query.
- Database_Driver_MySQLI::quote_table - Quote a database table name and adds the table prefix if needed.
- Database_Driver_MySQLI::create_database - 创建一个数据库
继承自父类的方法和变量
- Database_Driver::__construct
- Database_Driver::__destruct
- Database_Driver::connection_id - 获取当前连接的唯一ID
- Database_Driver::transaction - 获取事务对象
- Database_Driver::last_query - 最后查询的SQL语句
连接数据库
$use_connection_type 默认不传为自动判断,可传true/false,若传字符串(只支持a-z0-9的字符串),则可以切换到另外一个连接,比如传other,则可以连接到$this->_connection_other_id所对应的ID的连接
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$use_connection_type |
boolean |
是否使用主数据库 | null |
获取当前连接
mysqli
检查连接是否可用
防止因长时间不链接而导致连接丢失的问题 MySQL server has gone away
关闭链接
切换表
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$database |
string |
Database |
void
构建SQL语句
设置编码
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$charset |
string |
$charset |
void|boolean
Sanitize a string by escaping characters that could cause an SQL injection attack.
$value = $db->escape('any string');
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value to quote |
string
查询
$use_connection_type 默认不传为自动判断,可传true/false,若传字符串(只支持a-z0-9的字符串),则可以切换到另外一个连接,比如传other,则可以连接到$this->_connection_other_id所对应的ID的连接
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$sql |
string |
查询语句 | |
$as_object |
string |
是否返回对象 | null |
$use_connection_type |
boolean |
是否使用主数据库,不设置则自动判断 | null |
Database_Driver_MySQLI_Result
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
Quote a database table name and adds the table prefix if needed.
$table = $db->quote_table($table);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
mixed |
Table name or array(table, alias) | |
$auto_as_table |
unknown |
bool false |
string
创建一个数据库
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$database |
string |
$database | |
$charset |
string |
编码,不传则使用数据库连接配置相同到编码 | null |
$collate |
string |
整理格式 | null |
boolean
Compile the SQL query and return it.
string
Compiles an array of ORDER BY statements into an SQL partial.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$columns |
object |
Database instance |
string
Compiles an array of conditions into an SQL partial. Used for WHERE and HAVING.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$conditions |
object |
Database instance | |
$parameters |
array |
Condition statements |
string
Compiles an array of JOIN statements into an SQL partial.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$joins |
object |
Database instance |
string
Compiles an array of set values into an SQL partial. Used for UPDATE.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$values |
object |
Database instance | |
$parameters |
array |
Updated values |
string
初始化所有的as_table
格式化高级查询参数到select里
获取当前连接的唯一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 |