作者 邓超

x

@@ -24,7 +24,7 @@ class bodySql { @@ -24,7 +24,7 @@ class bodySql {
24 * @time 2023/3/23 10:15 24 * @time 2023/3/23 10:15
25 */ 25 */
26 public static function first(int $id):string { 26 public static function first(int $id):string {
27 - return "select * from `".static::$table."` where `lists_id` = {$id} limit 1"; 27 + return "select * from `".static::$table."` where `lists_id` = ".$id." limit 1";
28 } 28 }
29 29
30 /** 30 /**
@@ -35,7 +35,7 @@ class bodySql { @@ -35,7 +35,7 @@ class bodySql {
35 * @time 2023/3/23 10:15 35 * @time 2023/3/23 10:15
36 */ 36 */
37 public static function has(int $id){ 37 public static function has(int $id){
38 - return "select count(*) from `".static::$table."` where `lists_id` = {$id} limit 1"; 38 + return "select count(*) from `".static::$table."` where `lists_id` = ".$id." limit 1";
39 } 39 }
40 40
41 41
@@ -48,11 +48,13 @@ class bodySql { @@ -48,11 +48,13 @@ class bodySql {
48 * @time 2023/4/10 17:30 48 * @time 2023/4/10 17:30
49 */ 49 */
50 public static function insertOrUpdate(DbPool $db,$data){ 50 public static function insertOrUpdate(DbPool $db,$data){
51 - try {  
52 - return $db->insert(bodySql::$table,$data,false);  
53 - }catch (\Throwable $e){ 51 +
  52 + if($db->count(self::has($data['lists_id']))){
54 return $db->update(bodySql::$table,$data,dbWhere(['lists_id' => $data['lists_id']]),false); 53 return $db->update(bodySql::$table,$data,dbWhere(['lists_id' => $data['lists_id']]),false);
  54 + }else{
  55 + return $db->insert(bodySql::$table,$data,false);
55 } 56 }
  57 +
56 } 58 }
57 59
58 60