db_bridge/mysql_db.cpp
changeset 22 0db9235d68d9
parent 20 5fec678f931b
child 40 be3f5582b839
equal deleted inserted replaced
21:403742321c65 22:0db9235d68d9
     6 #include <mysql_db.h>
     6 #include <mysql_db.h>
     7 #include <console.h>
     7 #include <console.h>
     8 
     8 
     9 MySQL_DB::MySQL_DB (std::string srv, std::string usr, std::string pwd, std::string db)
     9 MySQL_DB::MySQL_DB (std::string srv, std::string usr, std::string pwd, std::string db)
    10 {
    10 {
    11     server = srv;
    11     server = (srv != "") ? srv : "localhost";
    12     user = (usr != "") ? usr : getenv ("USER");
    12     user = (usr != "") ? usr : getenv ("USER");
    13     password = pwd;
    13     password = pwd;
    14     database = db;
    14     database = db;
    15     conn = mysql_init (NULL);
    15     conn = mysql_init (NULL);
    16 
    16 
    17     if (server != "" && pwd == "") {
    17     if (pwd == "") {
    18         std::cout << "Passwort von " << user << "@" << server << ": ";
    18         std::cout << "Passwort von " << user << "@" << server << ": ";
    19         Console::getpass (password);
    19         Console::getpass (password);
    20     }
    20     }
    21 }
    21 }
    22 
    22 
    28     }
    28     }
    29 }
    29 }
    30 
    30 
    31 bool MySQL_DB::connect ()
    31 bool MySQL_DB::connect ()
    32 {
    32 {
    33     std::cerr << "Verbindungsparameter:" << " host=" << ((server != "") ? server : "LOCAL")
    33     std::cerr << "Verbindungsparameter:" << " host=" << server
    34         << " user=" << user << " password=" << password << " database=" << database << std::endl;
    34         << " user=" << user << " password=" << password << " database=" << database << std::endl;
    35 
    35 
    36     if (!mysql_real_connect (conn, server.c_str (), user.c_str (), password.c_str (), database.c_str (), 0, NULL, 0)) {
    36     if (!mysql_real_connect (conn, server.c_str (), user.c_str (), password.c_str (), database.c_str (), 0, NULL, 0)) {
    37         std::cerr << server << ": " << mysql_error (conn) << std::endl;
    37         std::cerr << server << ": " << mysql_error (conn) << std::endl;
    38         return false;
    38         return false;