#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; }
mysql.h
#include <mysql.h> // or #include "mysql.h"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)