annotate db.h @ 0:831599184108
inital commit
can increment the time in the database
author |
meillo@marmaro.de |
date |
Mon, 12 May 2008 21:24:20 +0200 |
parents |
|
children |
32c4212f05d9 |
rev |
line source |
meillo@0
|
1 /*
|
meillo@0
|
2 * data for the database connection
|
meillo@0
|
3 */
|
meillo@0
|
4
|
meillo@0
|
5 char* server = "localhost";
|
meillo@0
|
6 char* user = "garten";
|
meillo@0
|
7 char* password = "gras";
|
meillo@0
|
8 char* database = "garten";
|
meillo@0
|
9
|
meillo@0
|
10 MYSQL* conn;
|
meillo@0
|
11 MYSQL_RES* result;
|
meillo@0
|
12 MYSQL_ROW row;
|
meillo@0
|
13
|
meillo@0
|
14
|
meillo@0
|
15 void db_connect() {
|
meillo@0
|
16 conn = mysql_init(NULL);
|
meillo@0
|
17
|
meillo@0
|
18 /* Connect to database */
|
meillo@0
|
19 if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
|
meillo@0
|
20 fprintf(stderr, "%s\n", mysql_error(conn));
|
meillo@0
|
21 exit(1);
|
meillo@0
|
22 }
|
meillo@0
|
23 }
|
meillo@0
|
24
|
meillo@0
|
25
|
meillo@0
|
26 void db_close() {
|
meillo@0
|
27 /* close connection */
|
meillo@0
|
28 mysql_close(conn);
|
meillo@0
|
29 }
|
meillo@0
|
30
|
meillo@0
|
31
|
meillo@0
|
32 void db_query(char* query) {
|
meillo@0
|
33 int error;
|
meillo@0
|
34 /* send SQL query */
|
meillo@0
|
35 error = mysql_query(conn, query);
|
meillo@0
|
36 printf("query: %s\nerror: %d / %d\n", query, error, mysql_errno(conn));
|
meillo@0
|
37 if (error != 0) {
|
meillo@0
|
38 fprintf(stderr, "E: %s\n", mysql_error(conn));
|
meillo@0
|
39 }
|
meillo@0
|
40 }
|