diff options
author | Andi Shyti <andi@etezian.org> | 2012-09-02 02:12:08 +0200 |
---|---|---|
committer | Andi Shyti <andi@etezian.org> | 2012-09-02 02:12:08 +0200 |
commit | fdb1692c4e93ec4a71453d5d6c319fe1d6405e60 (patch) | |
tree | 0f6142f3858f3f79f00d13097a73b60f89b37476 /src/db_user.c |
accman: git repo created
Signed-off-by: Andi Shyti <andi@etezian.org>
Diffstat (limited to 'src/db_user.c')
-rw-r--r-- | src/db_user.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/db_user.c b/src/db_user.c new file mode 100644 index 0000000..1a851c8 --- /dev/null +++ b/src/db_user.c @@ -0,0 +1,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); +} |