-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbDrop.c
42 lines (36 loc) · 930 Bytes
/
dbDrop.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
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <mysql.h>
MYSQL *conn;
char * drop_tables = "drop tables user, item, bid_history, transaction, watched;";
// Initialize mysql
void sql_init() {
if (conn==NULL) {
printf("mysql_init: %s\n", mysql_error(conn));
exit(1);
}
}
// Connect to database
void sql_connect() {
if (mysql_real_connect(conn, "localhost", "db16314728", "970321", "db16314728", 0, NULL, 0)==NULL){
mysql_close(conn);
printf("mysql_real_connect: %s\n", mysql_error(conn));
exit(1);
}
}
void query(char * sqlquery) {
if (mysql_query(conn, sqlquery)){
printf("mysql_query: %s\n", mysql_error(conn));
mysql_close(conn);
exit(1);
}
}
int main(int argc, char* argv[]) {
conn = mysql_init(NULL);
// Initialize mysql
sql_init();
// Connect to database
sql_connect();
// Implement DDL
query(drop_tables);
return 0;
}