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
| #include <sys/time.h>
#include <stdio.h>
#include <mysql/mysql.h>
#include <config-win.h>
int main(char **args) {
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL *connection, mysql;
int state;
/* connect to the MySQL database at my.server.com */
mysql_init(&mysql);
connection =mysql_real_connect(MYSQL *mysql, const char *91.121.***.***, const char *user, const char *passe, const char *my db,
unsigned int 3306, const char *0, unsigned int *0)
/* check for a connection error */
IF (connection == NULL) {
/* print the error message */
printf(mysql_error(&mysql));
RETURN 1;
}
state = mysql_query(connection,
"SELECT id FROM membres");
IF (state != 0) {
printf(mysql_error(connection));
RETURN 1;
}
/* must call mysql_store_result() before can issue any other query calls */
result = mysql_store_result(connection);
printf("Rows: %d\n", mysql_num_rows(result));
/* process each row in the result set */
while ( ( row = mysql_fetch_row(result)) != NULL ) {
printf("id: %s, val: %s\n",(row[0] ? row[0] : "NULL"),(row[1] ? Row[1] : "NULL"));
}
/* free the result set */
mysql_free_result(result);
/* close the connection */
mysql_close(connection);
printf("Done.\n");
} |
Partager