#include <stdio.h>
#include "tuved.h"
MYSQL *conn = 0x0;
int dbInit() {
conn = mysql_init(NULL);
if (conn == NULL) {
writeLog(0,"mysql_init() failed (probably out of memory)\n.");
return(0x1);
}
if (!mysql_real_connect(conn,MYSQL_HOST_NAME,MYSQL_USERNAME,MYSQL_PASSWORD,MYSQL_DB_NAME,0,NULL,0)) {
writeLog(0,"mysql_real_connect() failed: Error %u (%s)\n.", mysql_errno(conn), mysql_error(conn));
return(0x1);
}
writeLog(0,"Sucessful connection to the MySQL Database.\n");
return(0x0);
}
MYSQL_RES *dbQuery(const char *query) {
MYSQL_RES *res_set = 0x0;
writeLog(0,"Query: %s\n",query);
if (mysql_query(conn,query) != 0x0) {
writeLog(0,"mysql_query() failed: Error %u (%s)\n.", mysql_errno(conn), mysql_error(conn));
return(0x0);
}
res_set = mysql_store_result(conn);
if (res_set != 0x0) {
return(res_set);
}
return (0x0);
}