bodySql.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Model;
use Lib\DbPool;
/**
* body
* @author:dc
* @time 2023/3/23 10:13
* Class bodySql
* @package Model
*/
class bodySql {
public static $table = 'bodies';
/**
*
* @param int $id
* @return string
* @author:dc
* @time 2023/3/23 10:15
*/
public static function first(int $id):string {
return "select * from `".static::$table."` where `lists_id` = ".$id." limit 1";
}
/**
* has
* @param int $id
* @return string
* @author:dc
* @time 2023/3/23 10:15
*/
public static function has(int $id){
return "select count(*) from `".static::$table."` where `lists_id` = ".$id." limit 1";
}
/**
* 插入或者更新
* @param DbPool $db
* @param $data
* @return int
* @author:dc
* @time 2023/4/10 17:30
*/
public static function insertOrUpdate(DbPool $db,$data){
if($db->count(self::has($data['lists_id']))){
return $db->update(bodySql::$table,$data,dbWhere(['lists_id' => $data['lists_id']]),false);
}else{
return $db->insert(bodySql::$table,$data,false);
}
}
}