简易好用的mysqli驱动器与结果集,带自动事务,参数转义
example.php 里有范例代码
$mysqli = new MysqliDriver(['username' => 'root', 'password' => '123456', 'database' => 'test']);
$mysqli = new MysqliDriver();
$conf = ['username' => 'root', 'password' => '123456', 'database' => 'test'];
$mysqli->connect($conf);
$mysqli = new MysqliDriver();
$mysqli->connect();
select
$query = $mysqli->query('select * from `money`');
print_r($query->result());
update insert delete
$status = $mysqli->query('update `money` set number = number - ? where uid = ?', 10, 100);
if($status){
echo $mysqli->affectedRows;
}
返回全部记录,对象
$query = $mysqli->query('select * from `money`');
print_r($query->result());
返回全部记录,数组
$query = $mysqli->query('select * from `money`');
print_r($query->result(Library\MysqliResult::MYSQLI_ARRAY));
返回单独一行结果。如果你的查询不止一行结果,它只返回第一行
$query = $mysqli->query('select * from `money`');
print_r($query->row());
事物中的sql执行失败,会自动回滚
注意: 默认update/insert/delete的affected_rows为0时事物也会自动回滚,如果你不想这样,请配置MysqliDriver::backZeroAffect = false;
$mysqli->transStart();
$mysqli->query('update `money` set number = number - ? where uid = ?', 10, 100);
$mysqli->query('insert `history`(uid, number) values(?, ?)', 100, -10);
$mysqli->transComplete();
echo 'Transaction execution status: ' . ($mysqli->transStatus() ? 'true' : 'false');