Bonjour,
Depuis plusieurs jours je tente de me connecter à ma base de données sous Linux. J'ai écrit un programme en c utilisant la bibliothèque mysql.h (MySQL-client-5.1.43-1.glibc23.i386.rpm) l’installation me semble ok puisque il s’agit d’un rpm, et le tous semble s’avoir installé dans :
/usr/include/mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit
Voici le chemin du fichier mysql.h
/usr/include/mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include/mysql.h
A la compilation de nombreuses erreur y sont générés les voici.
Avec #include <mysql.h>
gcc mysql-c-api_c.c -o mysql-c-api_c
mysql-c-api_c.c:6:19: erreur: mysql.h : Aucun fichier ou dossier de ce type
mysql-c-api_c.c: In function 'main':
mysql-c-api_c.c:10: erreur: 'MYSQL' undeclared (first use in this function)
mysql-c-api_c.c:10: erreur: (Each undeclared identifier is reported only once
mysql-c-api_c.c:10: erreur: for each function it appears in.)
mysql-c-api_c.c:10: erreur: 'conn' undeclared (first use in this function)
mysql-c-api_c.c:11: erreur: 'MYSQL_RES' undeclared (first use in this function)
mysql-c-api_c.c:11: erreur: 'res' undeclared (first use in this function)
mysql-c-api_c.c:12: erreur: 'MYSQL_ROW' undeclared (first use in this function)
mysql-c-api_c.c:12: erreur: expected ';' before 'row'
mysql-c-api_c.c:25: attention : incompatible implicit declaration of built-in function 'exit'
mysql-c-api_c.c:31: attention : incompatible implicit declaration of built-in function 'exit'
mysql-c-api_c.c:38: erreur: 'row' undeclared (first use in this function)
Avec #include </mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include/mysql.h>
gcc mysql-c-api_c.c -o mysql-c-api_c
mysql-c-api_c.c:6:77: erreur: /mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include/mysql.h : Aucun fichier ou dossier de ce type
mysql-c-api_c.c: In function 'main':
mysql-c-api_c.c:10: erreur: 'MYSQL' undeclared (first use in this function)
mysql-c-api_c.c:10: erreur: (Each undeclared identifier is reported only once
mysql-c-api_c.c:10: erreur: for each function it appears in.)
mysql-c-api_c.c:10: erreur: 'conn' undeclared (first use in this function)
mysql-c-api_c.c:11: erreur: 'MYSQL_RES' undeclared (first use in this function)
mysql-c-api_c.c:11: erreur: 'res' undeclared (first use in this function)
mysql-c-api_c.c:12: erreur: 'MYSQL_ROW' undeclared (first use in this function)
mysql-c-api_c.c:12: erreur: expected ';' before 'row'
mysql-c-api_c.c:25: attention : incompatible implicit declaration of built-in function 'exit'
mysql-c-api_c.c:31: attention : incompatible implicit declaration of built-in function 'exit'
mysql-c-api_c.c:38: erreur: 'row' undeclared (first use in this function)
Avec #include <mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include/mysql.h>
gcc mysql-c-api_c.c -o mysql-c-api_c
mysql-c-api_c.c: In function 'main':
mysql-c-api_c.c:25: attention : incompatible implicit declaration of built-in function 'exit'
mysql-c-api_c.c:31: attention : incompatible implicit declaration of built-in function 'exit'
/home/stephanepierre/tmp/ccHZ50qe.o: In function `main':
mysql-c-api_c.c:(.text+0x35): undefined reference to `mysql_init'
mysql-c-api_c.c:(.text+0x77): undefined reference to `mysql_real_connect'
mysql-c-api_c.c:(.text+0x86): undefined reference to `mysql_error'
mysql-c-api_c.c:(.text+0xbf): undefined reference to `mysql_query'
mysql-c-api_c.c:(.text+0xce): undefined reference to `mysql_error'
mysql-c-api_c.c:(.text+0xff): undefined reference to `mysql_use_result'
mysql-c-api_c.c:(.text+0x130): undefined reference to `mysql_fetch_row'
mysql-c-api_c.c:(.text+0x144): undefined reference to `mysql_free_result'
mysql-c-api_c.c:(.text+0x14f): undefined reference to `mysql_close'
collect2: ld a retourné 1 code d'état d'exécution
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48 /* J'ai tente ceci #include <mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include/mysql.h> et #include </mysql-connector-c-6.0.2-linux-glibc2.3-x86-32bit/include/mysql.h> */ #include <mysql.h> #include <stdio.h> int main(void) { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; /* Change me */ char *server = "localhost"; char *user = "root"; char *password = "PASSWORD"; char *database = "mysql"; 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]); /* close connection */ mysql_free_result(res); mysql_close(conn); return 0; }
Partager