-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySql.cpp
More file actions
57 lines (48 loc) · 1.32 KB
/
MySql.cpp
File metadata and controls
57 lines (48 loc) · 1.32 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
#include "MySql.hpp"
//#include <string>
namespace MySqlCon {
QueryResult execSQLQuery(
MYSQL* conn,
const std::string& query
) {
QueryResult r{ true, nullptr };
if (mysql_query(conn, query.c_str())) {
printf("MySQL error: %s\n", mysql_error(conn));
//printf("FAILED SQL QUERY!!!!\n");
r.success = false;
return r;
}
r.res = mysql_use_result(conn);
return r;
}
void CloseConnect(MYSQL* mysql)
{
if (mysql)
mysql_close(mysql);
}
MYSQL* GetConnection() {
uint8_t ssl_disabled = 0;
MYSQL* mysql = mysql_init(nullptr);
if (!mysql)
{
std::cout << "err init" << std::endl;
return nullptr;
}
mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &ssl_disabled);
if (!mysql_real_connect(
mysql,
"127.0.0.1",
"root",
"",
"masterserver_2025",
3306,
nullptr,
0))
{
std::cout << "err connect: " << mysql_error(mysql) << std::endl;
mysql_close(mysql);
return nullptr;
}
return mysql;
}
}