2 \brief Database storage for OCK's promo handler
6 ----------------------------------------------------------------------------*/
8 #include <stdio.h> //print
9 #include <string.h> //mem
11 #include <mysql/mysql.h>
16 int db_insert(char*,char*,char*,char*);
23 #define HOST "localhost"
25 #define PASS "#0CK0r34!"
26 #define DATABASE "ock_db"
30 #define DATTABLE "promo_submissions"
32 "id not null auto_increment," \
33 "firstname varchar (32) not null," \
34 "lastname varchar (32) not null," \
35 "email varchar (64) not null," \
36 "phone varchar (16) not null," \
38 { mysql
= mysql_init(NULL
);
39 if ((mysql
= mysql_real_connect(mysql
, HOST
, USER
, PASS
, DATABASE
, PORT
, SOCKET
, FLAGS
)) == NULL
)
40 { fprintf(stderr
,"Failed to establish connection to db.\n");
43 if (mysql_query(mysql
, "SHOW TABLES LIKE '" DATTABLE
"';"))
44 { fprintf(stderr
,"Initial query failed\n");
47 if (mysql_num_rows(mysql_use_result(mysql
)) < 1)
48 if (mysql_query(mysql
, "create table " DATTABLE
" (" DTABFMT
");"))
49 { fprintf(stderr
,"Failed to create table.\n");
63 "INSERT INTO " DATTABLE \
64 " VALUES ('%s','%s','%s','%s')" \
65 , fname, lname, email, phone
66 #define INSERT_ERR "SQL Insertion Failed for %s %s - %s %s\n" \
67 , fname, lname, email, phone
68 { char sqlinsert
[256];
69 sprintf(sqlinsert
, INSERT_FMT
);
70 if (mysql_query(mysql
, sqlinsert
))
71 { fprintf(stderr
, INSERT_ERR
);