#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "c:\mysql\include\mysql.h"
//------------------------------------------------------------
#define HOST "sql.free.fr"
#define LOGIN "***" //<-mon login
#define MDP "***" //<-mon mot de passe
#define TARGET_DB "***" //<-idem
//------------------------------------------------------------
static void exiterr(int exitcode);
//------------------------------------------------------------
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
//------------------------------------------------------------
int main(void)
{
unsigned int i = 0;
mysql_init(&mysql);
if (!(mysql_real_connect(&mysql,HOST,LOGIN,MDP,TARGET_DB,0,NULL,0)))
exiterr(1);
if (mysql_select_db(&mysql,TARGET_DB))
exiterr(2);
if (mysql_query(&mysql,"SELECT * FROM user" ))
exiterr(3);
if (!(res = mysql_store_result(&mysql)))
exiterr(4);
while((row = mysql_fetch_row(res))) {
for (i=0 ; i < mysql_num_fields(res); i++){
printf("%s ",row[i]);
}
printf("\n" );
}
if (!mysql_eof(res))
exiterr(5);
mysql_free_result(res);
mysql_close(&mysql);
printf("\n\nAppuyez sur une touche pour quitter :" );
getchar();
}
//------------------------------------------------------------
static void exiterr(int exitcode){
fprintf( stderr, "%s\n", mysql_error(&mysql) );
exit( exitcode );
}
|