Salut, je veux connecter mon programme C à une base de donnée sous windows 7. J'ai installé mysql-connector-c-noinstall-6.0.2-win32-vs2005. mais je sais pas comment l'inclure
voici le code en C :
Merci pour votre aideCode:#include <stdio.h> #include <mysql.h> #define host "localhost" #define username "root" #define password "viswa" #define database "dbase" MYSQL *conn; int main() { MYSQL_RES *res_set; MYSQL_ROW row; conn = mysql_init(NULL); if( conn == NULL ) { ` printf("Failed to initate MySQL\n"); return 1; } if( ! mysql_real_connect(conn,host,username,password,database,0,NULL,0) ) { printf( "Error connecting to database: %s\n", mysql_error(conn)); return 1; } unsigned int i; mysql_query(conn,"SELECT name, email, password FROM users"); res_set = mysql_store_result(conn); unsigned int numrows = mysql_num_rows(res_set); unsigned int num_fields = mysql_num_fields(res_set); while ((row = mysql_fetch_row(res_set)) != NULL) { for(i = 0; i < num_fields; i++) { printf("%s\t", row[i] ? row[i] : "NULL"); } printf("\n"); } mysql_close(conn); return 0; }
-----