-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmysql.c
executable file
·33 lines (25 loc) · 899 Bytes
/
mysql.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*****************************************************
* Created by Michael Morrison *
* *
* This implementation of MySQL is not thread-safe *
* *
*****************************************************/
#include <mysql.h>
#include "stdh.h"
#include "mysql.h"
MYSQL *mysql;
// this should only be called once...
int connect_db() {
mysql = mysql_init(NULL);
if(!mysql_real_connect(mysql, DB_IP, DB_USER, DB_PASSWORD, DB_NAME, 0, NULL, 0)) {
logit(LOG_ERROR, "Error %u: %s", mysql_errno(mysql), mysql_error(mysql));
return 0;
}
logit(LOG_NORMAL, "Connected as %s@%s to %s.", DB_USER, DB_IP, DB_NAME);
return 1;
}
MYSQL_RES *query(char *str) {
if(!mysql_query(mysql, str))
return mysql_store_result(mysql);
return 0;
}