#### 二、 數據庫操作類
引流寶的所有數據庫操作使用自寫的PDO操作類
具體curd操作請閱讀這個操作類的使用:
```
<?php
header("Content-type:text/html;charset=utf-8");
// 引入類
include './db.class.php';
// 數據庫配置
$config = [
'db_host' => 'localhost', // 數據庫地址
'db_port' => 3306, // 默認mysql數據庫端口
'db_name' => 'test', // 數據庫名字
'db_user' => 'root', // 數據庫用戶名
'db_pass' => 'root', // 數據庫密碼
'db_prefix' => '', // 表前綴
];
// 實例化類
$db = new DB_API($config);
// 表名
$article = $db->set_table('article');
// 新增數據
$newdata = ['title'=>'this is a title'];
$r = $article->add($newdata);
if($r){
echo '新增成功!';
}else{
echo '操作失敗!';
}
// 查詢數據
$where = ['id'=>3];
$find = $article->find($where); //查詢一條數據
$find = $article->findAll($where); // 查詢多條數據
print_r($find);
// 更新數據
$where = ['title'=>'hello world666'];
$update = $article->update($where,['id'=>1]);
if($update ){
echo '更新成功!';
// 查詢并打印
$newdata = $article->find('id=1');
print_r($newdata);
}else{
echo '更新失敗!';
}
// 刪除數據
$where = ['id'=>1];
$del = $article->delete($where);
if($del){
echo '刪除成功!';
}else{
echo '刪除失敗!';
}
// 獲取符合條件的記錄數
$where = ['author'=>'TANKING'];
$count = $article->getCount($where);
echo $count;
// 執行原生SQL語句
$sql = 'select * from article where id=3';
$lists = $article->findSql($sql);
print_r($lists);
// 根據條件查詢出對應的字段的值
$where = ['id'=>1];
$res = $article->getField($where,'title');
if ($res) {
echo $res;
}else{
echo "沒有數據";
}
// 高級查詢
// $conditions查詢條件
// $order排序方法
// $fields指定字段
// $limit查詢條數
$res = $article->findAll($conditions=null,$order='id asc',$fields=null,$limit=null);
if ($res) {
print_r($res);
}else{
print_r("沒有數據");
}
```