Commit 8cc3fc6f authored by denis's avatar denis

20160408

Initial commit. Basic folder structure, universal makefile and basic
routines for connecting to a mysql database
parents
Pipeline #1592238 skipped
CC = gcc
SRCPATH = $(wildcard src/*.c)
OBJPATH = $(addprefix build/,$(notdir $(SRCPATH:.c=.o)))
INCLUDES = -I/usr/include/mysql
LIBS = -L/usr/lib/mysql -lmysqlclient -lm
CFLAGS = -lm -Wall -O2 -L/usr/lib/mysql/ -lmysqlclient
all:ichinscratchy
ichinscratchy: $(OBJPATH)
$(CC) -o $@ $^ $(LIBS)
build/%.o: src/%.c
$(CC) -c $(INCLUDES) -o $@ $<
clean:
rm -f $(OBJPATH)
rm -f ichinscratchy
#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
MYSQL *mysql;
void check_mysql_error()
{
if (mysql_errno(mysql) != 0)
{
fprintf(stderr, "error %u: %s\n", mysql_errno(mysql), mysql_error(mysql));
exit(1);
}
}
void connect_mysql_database()
{
mysql=mysql_init(mysql);
check_mysql_error();
mysql_real_connect(
mysql, /* Pointer to MYSQL-handler */
"localhost", /* hostname */
"werwurm", /* username */
"slayer1", /* password */
"dvd_archiv", /* database name */
0, /* port (default=0) */
NULL, /* Socket (default=NULL) */
0); /* no flags */
check_mysql_error();
}
void close_mysql_connection()
{
mysql_close(mysql);
check_mysql_error();
}
void check_mysql_error();
void connect_mysql_database();
void close_mysql_connection();
#include <stdio.h>
#include <stdlib.h>
#include "database.h"
int main (int argc, char *argv[]) {
/* connect to mysql Server */
fprintf(stderr,"\nConnecting to database... ");
connect_mysql_database();
fprintf(stderr,"connected!\n");
close_mysql_connection();
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment