· 6 years ago · Dec 17, 2019, 08:52 PM
1class dbManager {
2
3 constructor() {
4
5 }
6
7 function Connect(host, user, pass, dbname){
8
9 this.host = host;
10 this.user = user;
11 this.pass = pass;
12 this.dbname = dbname;
13
14 handler = mysql_connect(host, user, pass, dbname);
15
16 if(!handler)
17 {
18 Tools.AddLog("[dbManager] Nie udało się połączyć z bazą danych. Wyłączam serwer.", 2);
19 abort();
20 }
21
22 mysql_query(handler, "SET NAMES cp1250;");
23 mysql_query(handler, "SET CHARACTER_SET cp1250_polish_ci");
24 }
25
26 function CreateTables()
27 {
28 if(!handler)
29 this.Connect(this.host, this.user, this.pass, this.dbname);
30
31 mysql_query(handler, "CREATE TABLE IF NOT EXISTS `admins` (`ID` INT(11) NOT NULL AUTO_INCREMENT,`UserID` INT(11) NOT NULL,`Level` INT(11) NULL DEFAULT NULL,`ExpiryDate` BIGINT(20) NULL DEFAULT NULL,`Permanent` SMALLINT(6) NULL DEFAULT NULL,`SuspendedTo` BIGINT(20) NULL DEFAULT NULL, PRIMARY KEY (`ID`),INDEX `UserID` (`UserID`))COLLATE='cp1250_polish_ci';");
32 }
33
34 function Insert(query)
35 {
36 if(!handler)
37 this.Connect(this.host, this.user, this.pass, this.dbname);
38
39 local result = mysql_query(handler, query);
40
41 return result;
42 }
43
44 function Select(query)
45 {
46 if(!handler)
47 this.Connect(this.host, this.user, this.pass, this.dbname);
48
49 local result = mysql_query(handler, query);
50
51 return result;
52 }
53
54 function Delete(query)
55 {
56 if(!handler)
57 this.Connect(this.host, this.user, this.pass, this.dbname);
58
59 local result = mysql_query(handler, query);
60
61 return result;
62 }
63
64 function Update(query)
65 {
66 if(!handler)
67 this.Connect(this.host, this.user, this.pass, this.dbname);
68
69 local result = mysql_query(handler, query);
70
71 return result;
72 }
73
74 host = null;
75 user = null;
76 pass = null;
77 dbname = null;
78
79 handler = null;
80}