34 lines
764 B
C++
34 lines
764 B
C++
#include "Database.hpp"
|
|
#include "Config.hpp"
|
|
|
|
Database::Database(){
|
|
Config conf("config.txt");
|
|
std::string pgsqlConnectingString;
|
|
|
|
pgsqlConnectingString
|
|
.append(" host=").append(conf.getValue("db_host"))
|
|
.append(" dbname=").append(conf.getValue("db_name"))
|
|
.append(" user=").append(conf.getValue("db_user"))
|
|
.append(" password=").append(conf.getValue("db_pass"));
|
|
std::cout << pgsqlConnectingString << std::endl;
|
|
|
|
dbconn = PQconnectdb(pgsqlConnectingString.c_str());
|
|
}
|
|
|
|
void Database::execute(std::string cmd){
|
|
PQexec(dbconn, cmd.c_str());
|
|
}
|
|
|
|
PGresult* Database::fetch(std::string cmd){
|
|
PGresult *r = PQexec(dbconn, cmd.c_str());
|
|
return r;
|
|
|
|
// Don't forget to close after using this request
|
|
|
|
|
|
}
|
|
|
|
void Database::disconnect(){
|
|
PQfinish(dbconn);
|
|
}
|