From 44ac500361b95af71492dc319b186413420b72fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 15 Dec 2017 16:34:43 +0100 Subject: [PATCH 1/1] Initial C and PHP skeleton. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .gitignore | 25 +++++++++ TD5/C/Makefile | 82 +++++++++++++++++++++++++++ TD5/C/exemple_mysql_libmysqlclient.c | 83 ++++++++++++++++++++++++++++ TD5/PHP/testmysql.php | 33 +++++++++++ 4 files changed, 223 insertions(+) create mode 100644 .gitignore create mode 100644 TD5/C/Makefile create mode 100644 TD5/C/exemple_mysql_libmysqlclient.c create mode 100644 TD5/PHP/testmysql.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..435d966 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +*.static +*.dynamic +# for cygwin +*.exe + +*.o + +*.so +*.dylib +*.a +# for cygwin +*.dll +*.dll.a + +# atom linter +*.gch + +# editor trash +*.swp +*~ + +.build + +thumbs.db +*.DS_Store diff --git a/TD5/C/Makefile b/TD5/C/Makefile new file mode 100644 index 0000000..b5cebf8 --- /dev/null +++ b/TD5/C/Makefile @@ -0,0 +1,82 @@ +# Sample Makefile to build simple project. +# +# This Makefile expect all source files (.c) to be at the same level, in the +# current working directory. +# +# It will automatically generate dependencies, compile all files, and produce a +# binary using the provided name. +# +# Set BINARY_NAME to the name of the binary file to build. +# Set BUILD_TYPE to either debug or release +# +# Automatic dependencies code from: +# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr +BINARY_NAME=infovols +BUILD_TYPE=debug +#BUILD_TYPE=release + +# ==================================== +# DO NOT CHANGE STUFF BEYOND THIS LINE +# ==================================== + +all: $(BINARY_NAME) + +CC=gcc +LD=gcc + +WARN_FLAGS = -Wall -Wextra +STD_FLAG = -std=c11 + +ifeq ($(BUILD_TYPE),debug) +BUILDDIR := .build/debug +DEBUG_FLAG = -g +DEBUG = 1 +STRIP_FLAG = +OPTI_FLAG = -O0 +else +BUILDDIR := .build/release +DEBUG_FLAG = +DEBUG = 0 +STRIP_FLAG = -s +OPTI_FLAG = -O3 +endif + +CFLAGS := -DDEBUG=$(DEBUG) $(CFLAGS) $(WARN_FLAGS) $(STD_FLAG) $(OPTI_FLAG) $(DEBUG_FLAG) +LDFLAGS := $(LDFLAGS) $(STRIP_FLAG) + +OBJDIR := $(BUILDDIR)/objs +$(shell mkdir -p $(OBJDIR)) + +SRCS=$(wildcard *.c) +OBJS=$(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) + +DEPDIR := $(BUILDDIR)/deps +$(shell mkdir -p $(DEPDIR)) +DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td +POSTCOMPILE = mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d + +$(BINARY_NAME): $(OBJS) + @echo "[LD ] $@" + @$(LD) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJDIR)/%.o: %.c $(DEPDIR)/%.d + @echo "[C ] $*" + @$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@ + @$(POSTCOMPILE) + +$(DEPDIR)/%.d: ; + +.PRECIOUS: $(DEPDIR)/%.d + +include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS)))) + +clean: + @echo "[CLN]" + -@rm -r $(BUILDDIR) + -@rm $(BINARY_NAME) + +disassemble: $(BINARY_NAME) + objdump -d $< | less + +symbols: $(BINARY_NAME) + objdump -t $< | sort | less diff --git a/TD5/C/exemple_mysql_libmysqlclient.c b/TD5/C/exemple_mysql_libmysqlclient.c new file mode 100644 index 0000000..88e82da --- /dev/null +++ b/TD5/C/exemple_mysql_libmysqlclient.c @@ -0,0 +1,83 @@ +#include +#include +#include + +//il faut : libmysqlclient-dev + +//compilation : +// gcc testsqlc.c -o testsqlc -I/usr/include/mysql -lmysqlclient -L/usr/lib64/mysql + +//execution : +//./testsqlc + + +int main(void) { + MYSQL *conn; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_RES *result; + + char *server = ""; + char *user = ""; + char *password = ""; + char *database = ""; + + conn = mysql_init(NULL); + + /* Connect to database */ + if (!mysql_real_connect(conn, server, + user, password, database, 0, NULL, 0)) { + fprintf(stderr, "%s\n", mysql_error(conn)); + exit(1); + } + + /* send SQL query */ + if (mysql_query(conn, "show tables")) { + fprintf(stderr, "%s\n", mysql_error(conn)); + exit(1); + } + + res = mysql_use_result(conn); + + /* output table name */ + printf("MySQL Tables in mysql database:\n"); + while ((row = mysql_fetch_row(res)) != NULL) + printf("%s \n", row[0]); + + /* query */ + if (mysql_query(conn, "SELECT * FROM Usine")) + { + fprintf(stderr, "%s\n", mysql_error(conn)); + exit(1); + } + + result = mysql_store_result(conn); + + if (result == NULL) + { + fprintf(stderr, "%s\n", mysql_error(conn)); + exit(1); + } + + int num_fields = mysql_num_fields(result); + int i; + + printf("\nTable Usine :\n"); + printf("NU\tNomU\tVille\n"); + + while ((row = mysql_fetch_row(result))) + { + for(i = 0; i < num_fields; i++) + { + printf("%s\t", row[i] ? row[i] : "NULL"); + } + printf("\n"); + } + + /* close connection */ + mysql_free_result(res); + mysql_close(conn); + + return 0; +} + diff --git a/TD5/PHP/testmysql.php b/TD5/PHP/testmysql.php new file mode 100644 index 0000000..8eec3f2 --- /dev/null +++ b/TD5/PHP/testmysql.php @@ -0,0 +1,33 @@ + + +
'; + $requete = "SELECT NumCl, NomCl, CodePosteCl, VilleCl FROM CLIENTS"; + if($result = mysql_query($requete)) { + echo "\n"; + echo "\n"; + while($ligne = mysql_fetch_row($result)) { + $code = $ligne[0]; + $nom = $ligne[1]; + $rue = $ligne[2]; + $ville = $ligne[3]; + echo "\n"; + } + echo "
Code_CLNomRueVille
$code$nom$rue$ville
\n"; + } else { + echo 'Erreur de requete'; + } + } else { + die('Echec de connexion a la base'); + } + mysql_close(); + echo '
Deconnexion.'; +} else { + die('Echec de connexion au serveur de bases de donnees'); +} +?> + + + -- 2.34.1