### 操作数据库(增改删查)
> 读取单条数据
```
$rs = $db -> select("id","ourphp_web","where id = 1");
//select("字段可以为*,多个字段用,隔开","表名","条件(可为空)")
echo $rs[0];
```
> 读取列表数据
```
$list = $db -> listgo("id","ourphp_web","where id = 1 order by id desc");
//listgo("字段可以为*,多个字段用,隔开","表名","条件(可为空)")
while($rs = $db -> whilego($list)){
echo $rs[0];
}
```
> 解析列表数据whilego
```
whilego($list,1) 第二个参数可不设,默认1(fetch_array),2(fetch_row),3(fetch_assoc)
while($rs = $db -> whilego($list,1)){
//这里写上业务逻辑,具体参考数据库文档
}
```
> 插入数据方式一
```
$db -> insert("ourphp_web","`name` = '".$_POST['name']."',`tel` = '2'","");
//insert("表名","插入内容","条件(可为空)");
```
> 插入数据方式二(一次插入多条)
```
组合记录:
$info = array(
"table" => "OP_Class,OP_Lang,OP_Title",
"data" => array(
array(13,"cn","插入测试"),
array(14,"cn","插入测试"),
array(15,"cn","插入测试"),
)
);
$db -> insertarray("ourphp_web",$info,"");
//insertarray("表名","插入组合变量$info","条件(可为空)");
```
> 获取插入记录ID
```
在$db -> insert或$db -> insertarray后面执行
$newid = $db -> insertid(); //可获取刚插入记录的ID
echo $newid;
```
> 更新记录
```
$db -> update("ourphp_web","`name` = '".$_POST['name']."',`tel` = '2'","where id = 1");
//update("表名","插入更新内容","条件(可为空)");
//注:如更新失败返回 0 或判断 false
```
> 删除记录
```
$db -> del("ourphp_web","where id = 1");
//del("表名","条件");
```
> 获取数据报错
```
$db -> error();
使用方法:$db -> select("*","ourphp_web","where id = 1") or die($db -> error());
```
> 删除表
```
$db -> drop("ourphp_web");
//drop("要删除的表名");
```
> 获取记录数
```
$db -> rows($list);
使用方法
$list = $db -> listgo("*","ourphp_web","order by desc");
$rows = $db -> rows($list);
echo $rows;
```