前一次操作影响的记录数。在Dao中使用
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->dao->db->affected_rows();
}
}
关闭连接。在Dao中使用
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->close();
}
}
错误信息。在Dao中使用
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->error();
}
}
从结果集中取得一行作为关联数组。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $result | Obj | 是 | 结果集对象 |
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
if (!$result) return false;
$temp = array();
while ($row = $this->dao->db->fetch_assoc($result)) {
$temp[] = $row;
}
}
}
从结果集中取得列信息并作为对。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $result | Obj | 是 | 结果集对象 |
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->fetch_fields($result);
}
}
根据数值来进行分表,一般情况下,可以根据UID来进行分表方法。自定义余数,例如:$default = 7 就是除以7来求余。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $num | Number | 是 | 数值 |
| $tbl | String | 是 | 模板前缀 |
| $default | Int | 否 | 求余数的数字 |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->fmod_identify(2343204, 'pw', $default = 7);
}
}
释放结果内存。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $result | Obj | 是 | 结果集对象 |
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->free_result($result);
}
}
该函数用来初始化DB,可以通过修改$db参数来初始化多数据库链接。一般情况下用户不需要使用该函数,InitPHP框架里面已经做掉了这部分功能。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $db | String | 否 | 需要链接到DB |
$this->dao->db->init_db($db = '')
获取上一INSERT的ID值。在Dao中使用
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->insert_id();
}
}
该一般在分表分库到时候,可以用这个函数来计算分表分库的方法。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $tbl | String | 是 | 表-库前缀 |
| $defaultId | String | 否 | 默认的表月份 |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->month_identify('pw');
}
}
结果集中的字段数量。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $result | Obj | 是 | 结果集对象 |
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->num_fields($result);
}
}
根据数值来进行分表,一般情况下,可以根据UID来进行分表方法。也可以自定义截取需要获取数值的位数,例如2位:00,01,02,03。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $num | Number | 是 | 数值 |
| $tbl | String | 是 | 模板前缀 |
| $default | Int | 否 | 默认截取长度 |
class testaDao extends Dao {
public $db = 'test';
public function test() {
echo $this->dao->db->num_identify(2343204, 'pw', $default = 2);
}
}
结果集中的行数。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $result | Obj | 是 | 结果集对象 |
class testaDao extends Dao {
public function test() {
$sql = sprintf("SELECT * FROM %s %s ORDER BY %s %s %s", $table_name, $where, $id_key, $sort, $limit);
$result = $this->dao->db->query($sql);
$this->db->num_rows($result);
}
}
执行SQL语句。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $sql | String | 是 | 数据库语句 |
class testaDao extends Dao {
public function test() {
$this->dao->db->query('SELECT * FROM table');
}
}
结果集中的行数。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $result | Obj | 是 | 结果集对象 |
| $num | Int | 是 | 条数 |
class testaDao extends Dao {
public function test() {
$this->dao->db->result($result, $num=1);
}
}
提交事务。在Dao中使用
class testaDao extends Dao {
public function test() {
$this->dao->db->transaction_start();
$r1 = $this->dao->db->query("select * from user where uid = 1");
$r2 = $this->dao->db->query("delete from user where uid = 1");
if ($r1 && $r2) {
$this->dao->db->transaction_commit();
} else {
$this->dao->db->transaction_rollback();
}
}
}
回滚事务。在Dao中使用
class testaDao extends Dao {
public function test() {
$this->dao->db->transaction_start();
$r1 = $this->dao->db->query("select * from user where uid = 1");
$r2 = $this->dao->db->query("delete from user where uid = 1");
if ($r1 && $r2) {
$this->dao->db->transaction_commit();
} else {
$this->dao->db->transaction_rollback();
}
}
}
开始事务。在Dao中使用
class testaDao extends Dao {
public function test() {
$this->dao->db->transaction_start();
$r1 = $this->dao->db->query("select * from user where uid = 1");
$r2 = $this->dao->db->query("delete from user where uid = 1");
if ($r1 && $r2) {
$this->dao->db->transaction_commit();
} else {
$this->dao->db->transaction_rollback();
}
}
}