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
|
#include <accman.h>
#include <mysql.h>
void db_insert_user(struct user u)
{
MYSQL *conn;
char mysql_query_str[1024];
conn = mysql_init(NULL);
if (!conn) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(EXIT_FAILURE);
}
if (!mysql_real_connect(conn, "localhost", "user", "password",
"mailserver", 0, NULL, 0)) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(EXIT_FAILURE);
}
snprintf(mysql_query_str, 1024,
"insert into virtual_users(domain_id, password, email) "
"values (1, '%s', '%s')", u.p, u.n);
if (mysql_query(conn, mysql_query_str)) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
mysql_close(conn);
}
|