-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.cc
55 lines (48 loc) · 1.39 KB
/
simple.cc
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
#include <mysql.h>
#include <string>
#include <iostream>
#include <unistd.h>
const char* user = "maxuser";
const char* password = "maxpwd";
const char* db = "test";
const char* host = "127.0.0.1";
int port = 4006;
int main(int argc, char** argv)
{
MYSQL* c = mysql_init(nullptr);
if (!mysql_real_connect(c, host, user, password, db, port, nullptr, 0))
{
std::cout << "Connect: " << mysql_error(c) << std::endl;
}
else
{
while (true)
{
if (mysql_query(c, "INSERT INTO test.t1 VALUES (1)"))
{
std::cout << "Query failed: " << mysql_error(c) << std::endl;
break;
}
else
{
//std::cout << "Press enter to continue..." << std::endl;
//std::string line;
//std::getline(std::cin, line);
if (mysql_query(c, "SELECT * FROM test.t1"))
{
std::cout << "Query failed: " << mysql_error(c) << std::endl;
break;
}
else if (auto* res = mysql_store_result(c))
{
while (auto row = mysql_fetch_row(res))
{
}
mysql_free_result(res);
}
}
}
}
mysql_close(c);
return 0;
}