garten

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/db.h	Mon May 12 21:24:20 2008 +0200
     1.3 @@ -0,0 +1,40 @@
     1.4 +/*
     1.5 + * data for the database connection
     1.6 + */
     1.7 +
     1.8 +char* server = "localhost";
     1.9 +char* user = "garten";
    1.10 +char* password = "gras";
    1.11 +char* database = "garten";
    1.12 +
    1.13 +MYSQL* conn;
    1.14 +MYSQL_RES* result;
    1.15 +MYSQL_ROW row;
    1.16 +
    1.17 +
    1.18 +void db_connect() {
    1.19 +	conn = mysql_init(NULL);
    1.20 +
    1.21 +	/* Connect to database */
    1.22 +	if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
    1.23 +		fprintf(stderr, "%s\n", mysql_error(conn));
    1.24 +		exit(1);
    1.25 +	}
    1.26 +}
    1.27 +
    1.28 +
    1.29 +void db_close() {
    1.30 +	/* close connection */
    1.31 +	mysql_close(conn);
    1.32 +}
    1.33 +
    1.34 +
    1.35 +void db_query(char* query) {
    1.36 +	int error;
    1.37 +	/* send SQL query */
    1.38 +	error = mysql_query(conn, query);
    1.39 +	printf("query: %s\nerror: %d / %d\n", query, error, mysql_errno(conn));
    1.40 +	if (error != 0) {
    1.41 +		fprintf(stderr, "E: %s\n", mysql_error(conn));
    1.42 +	}
    1.43 +}