Last Update (partial) have to link every file in the right place
This commit is contained in:
33
server/Database.cpp
Normal file
33
server/Database.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#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);
|
||||
}
|
Reference in New Issue
Block a user