database stuff

This commit is contained in:
kdeng00
2019-08-18 11:57:08 -04:00
parent 5230e69832
commit d26c16aa69
11 changed files with 211 additions and 48 deletions
+25
View File
@@ -0,0 +1,25 @@
#include "database/base_repository.h"
MYSQL* base_repository::setup_mysql_connection(database_connection details)
{
MYSQL *connection = mysql_init(NULL);
// connect to the database with the details attached.
if (!mysql_real_connect(connection,details.server.c_str(), details.username.c_str(), details.password.c_str(), details.database.c_str(), 0, NULL, 0)) {
printf("Conection error : %s\n", mysql_error(connection));
exit(1);
}
return connection;
}
MYSQL_RES* base_repository::perform_mysql_query(MYSQL *conn, std::string& query)
{
// send the query to the database
if (mysql_query(conn, query.c_str()))
{
printf("MySQL query error : %s\n", mysql_error(conn));
exit(1);
}
return mysql_use_result(conn);
}