remove db=null

This commit is contained in:
2026-09-01 20:51:57 +03:00
parent 22e3776892
commit ff437d082c
+6 -29
View File
@@ -113,7 +113,7 @@ CreateApi(function ($api) {
// according docs (UPPERCASE, MIN 3 MAX 10)
$db = db();
$results = FastDBReq($db, "SELECT * FROM classes WHERE classid = ?", [$classId]);
$db = null;
if (count($results) != 0) {
return $results[0];
} else {
@@ -130,7 +130,7 @@ CreateApi(function ($api) {
// according docs (UPPERCASE, MIN 3 MAX 10)
$db = db();
$results = FastDBReq($db, "SELECT userclassname FROM classes WHERE classid = ?", [$classId]);
$db = null;
if (count($results) != 0) {
return $results[0];
@@ -147,7 +147,7 @@ CreateApi(function ($api) {
$adminId = $req->data['adminId'];
$db = db();
$results = FastDBReq($db, "SELECT adminName FROM admins where adminid = ?", [$adminId]);
$db = null;
if (count($results) != 0) {
return $results[0];
@@ -164,7 +164,7 @@ CreateApi(function ($api) {
$adminId = $req->data['adminId'];
$db = db();
$results = FastDBReq($db, "SELECT adminPrems FROM admins where adminid = ?", [$adminId]);
$db = null;
if (count($results) != 0) {
return $results[0];
@@ -181,7 +181,7 @@ CreateApi(function ($api) {
$adminId = $req->data['adminId'];
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminid = ?", [$adminId]);
$db = null;
if (count($results) != 0) {
return $results[0];
@@ -218,7 +218,6 @@ CreateApi(function ($api) {
}
}
if ($has_full_rings) {
$db = null;
// with rings
return ['data' => $content, 'type' => 2];
} else {
@@ -229,7 +228,6 @@ CreateApi(function ($api) {
if ($rings !== null) {
$out = joinArraysByKey($content, $rings, true);
}
$db = null;
return ['data' => $out, 'type' => 1];
}
} else {
@@ -245,10 +243,8 @@ CreateApi(function ($api) {
if ($rings !== null) {
$out = joinArraysByKey($schedule, $rings);
}
$db = null;
return ['data' => $out, 'type' => 0];
} else {
$db = null;
return ['data' => []];
}
}
@@ -262,7 +258,6 @@ CreateApi(function ($api) {
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "админ не найден";
# end
@@ -293,7 +288,6 @@ CreateApi(function ($api) {
$rings = json_decode(findClosestDateSort($results, $day)['content'], true);
}
}
$db = null;
switch ($tab) {
case 0:
@@ -323,7 +317,6 @@ CreateApi(function ($api) {
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "админ не найден";
# end
@@ -334,7 +327,6 @@ CreateApi(function ($api) {
$newDataRaw = $req->data['newData'];
$newData = json_decode($newDataRaw, true);
// im too lazy to close db
switch ($tab) {
case 0: // changes
@@ -397,7 +389,6 @@ CreateApi(function ($api) {
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "админ не найден";
# end
@@ -417,10 +408,8 @@ CreateApi(function ($api) {
FastDBReq($db, 'DELETE FROM rings WHERE classId=? AND fromDate=?', [$classId, $day]);
break;
default:
$db = null;
return "you saved your live because you didn't know what tabs are here";
}
$db = null;
return true;
});
$api->on('/update_admin', "POST", function ($req) {
@@ -438,12 +427,10 @@ CreateApi(function ($api) {
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "админ не найден";
}
if (!$withSelf && !in_array($results[0]['adminPrems'], [-1, 2])) {
$db = null;
$req->res->code(400);
return 'нету прав';
}
@@ -462,7 +449,6 @@ CreateApi(function ($api) {
try {
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $adminId]);
} catch (PDOException) {
$db = null;
return "egor";
}
break;
@@ -483,16 +469,13 @@ CreateApi(function ($api) {
try {
FastDBReq($db, 'UPDATE admins SET adminName = ? WHERE adminId = ?', [$value, $person]);
} catch (PDOException) {
$db = null;
return "egor";
}
break;
default:
$db = null;
return "?";
}
}
$db = null;
return true;
});
@@ -505,12 +488,10 @@ CreateApi(function ($api) {
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "админ не найден";
}
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
$db = null;
$req->res->code(400);
return "недостаточно прав";
}
@@ -519,13 +500,12 @@ CreateApi(function ($api) {
$results = FastDBReq($db, "SELECT * FROM classes WHERE classId=?", [$classId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "класса не существует";
}
$classData = $results[0];
$adminsData = FastDBReq($db, "SELECT * FROM admins WHERE adminClass=?", [$classId]);
$db = null;
return ["status" => 1, "class" => $classData, "admins" => $adminsData];
});
@@ -539,12 +519,10 @@ CreateApi(function ($api) {
$db = db();
$results = FastDBReq($db, "SELECT * FROM admins WHERE adminId=?", [$adminId]);
if (count($results) == 0) {
$db = null;
$req->res->code(400);
return "админ не найден";
}
if (!in_array($results[0]['adminPrems'], [-1, 2])) {
$db = null;
$req->res->code(400);
return "недостаточно прав";
}
@@ -610,7 +588,6 @@ CreateApi(function ($api) {
FastDBReq($db, "DELETE FROM admins WHERE adminId=?", [$person]);
return true;
default:
$db = null;
return "?";
}
});