Properties

$hashCode

$hashCode : string

hashCode

Type

string

$instance

$instance : \PDO

连接对象

Type

\PDO

$option

$option : array

连接配置

Type

array

$lastSql

$lastSql : string

最后执行过的SQL语句

Type

string

$isCacheStatement

$isCacheStatement : boolean

是否缓存 Statement

Type

boolean

Methods

hashCode()

hashCode() 

__construct()

__construct(array  $option = array()) 

参数格式: [ 'host' => 'MySQL IP地址', 'username' => '数据用户', 'password' => '数据库密码', 'database' => '数据库名', 'port' => 'MySQL端口 默认3306 可选参数', 'timeout' => '建立连接超时时间', 'charset' => '字符集', 'options' => [], // PDO连接选项 ]

Parameters

array $option

__destruct()

__destruct() 

isConnected()

isConnected() : boolean

是否已连接

Returns

boolean

open()

open() : boolean

打开

Returns

boolean

close()

close() : void

关闭

getInstance()

getInstance() : \PDO

获取原对象实例

Returns

\PDO

beginTransaction()

beginTransaction() : boolean

启动一个事务

Returns

boolean

commit()

commit() : boolean

提交一个事务

Returns

boolean

rollBack()

rollBack(integer  $levels = null) : boolean

回滚事务 支持设置回滚事务层数,如果不设置则为全部回滚

Parameters

integer $levels

Returns

boolean

getTransactionLevels()

getTransactionLevels() : integer

获取事务层数

Returns

integer

inTransaction()

inTransaction() : boolean

检查是否在一个事务内

Returns

boolean

errorCode()

errorCode() : mixed

返回错误码

Returns

mixed

errorInfo()

errorInfo() : array

返回错误信息

Returns

array

lastSql()

lastSql() : string

获取最后一条执行的SQL语句

Returns

string

exec()

exec(string  $sql) : integer

执行一条 SQL 语句,并返回受影响的行数

Parameters

string $sql

Returns

integer

getAttribute()

getAttribute(mixed  $attribute) : mixed

取回一个数据库连接的属性

Parameters

mixed $attribute

Returns

mixed

setAttribute()

setAttribute(mixed  $attribute, mixed  $value) : boolean

设置属性

Parameters

mixed $attribute
mixed $value

Returns

boolean

lastInsertId()

lastInsertId(string  $name = null) : string

返回最后插入行的ID或序列值

Parameters

string $name

Returns

string

rowCount()

rowCount() : integer

返回受上一个 SQL 语句影响的行数

Returns

integer

prepare()

prepare(string  $sql, array  $driverOptions = array()) : \Imi\Db\Interfaces\IStatement

准备执行语句并返回一个语句对象

Parameters

string $sql
array $driverOptions

Throws

\Imi\Db\Exception\DbException

Returns

\Imi\Db\Interfaces\IStatement

query()

query(string  $sql) : \Imi\Db\Interfaces\IStatement

执行一条SQL语句,返回一个结果集作为PDOStatement对象

Parameters

string $sql

Throws

\Imi\Db\Exception\DbException

Returns

\Imi\Db\Interfaces\IStatement

buildDSN()

buildDSN() : string

构建DNS字符串

Returns

string