equal
deleted
inserted
replaced
6 #include <mysql_db.h> |
6 #include <mysql_db.h> |
7 |
7 |
8 MySQL_DB::MySQL_DB (std::string srv, std::string usr, std::string pwd, std::string db) |
8 MySQL_DB::MySQL_DB (std::string srv, std::string usr, std::string pwd, std::string db) |
9 { |
9 { |
10 server = srv; |
10 server = srv; |
11 user = usr; |
11 user = (usr != "") ? usr : getenv ("USER"); |
12 password = pwd; |
12 password = pwd; |
13 database = db; |
13 database = db; |
14 conn = mysql_init (NULL); |
14 conn = mysql_init (NULL); |
|
15 |
|
16 if (server != "" && pwd == "") { |
|
17 std::cout << "Passwort von " << user << "@" << server << ": "; |
|
18 std::getline (std::cin, password); |
|
19 } |
15 } |
20 } |
16 |
21 |
17 MySQL_DB::~MySQL_DB () |
22 MySQL_DB::~MySQL_DB () |
18 { |
23 { |
19 if (conn != NULL) { |
24 if (conn != NULL) { |
22 } |
27 } |
23 } |
28 } |
24 |
29 |
25 bool MySQL_DB::connect () |
30 bool MySQL_DB::connect () |
26 { |
31 { |
|
32 std::cerr << "Verbindungsparameter:" << " host=" << ((server != "") ? server : "LOCAL") |
|
33 << " user=" << user << " password=" << password << " database=" << database << std::endl; |
|
34 |
27 if (!mysql_real_connect (conn, server.c_str (), user.c_str (), password.c_str (), database.c_str (), 0, NULL, 0)) { |
35 if (!mysql_real_connect (conn, server.c_str (), user.c_str (), password.c_str (), database.c_str (), 0, NULL, 0)) { |
28 std::cerr << server << ": " << mysql_error (conn) << std::endl; |
36 std::cerr << server << ": " << mysql_error (conn) << std::endl; |
29 return false; |
37 return false; |
30 } |
38 } |
31 |
39 |