#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <mysql.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "";
char *database = "example";
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(0);
}
/* send SQL query */
if (mysql_query(conn, "SELECT * FROM viewmsg")) {
fprintf(stderr, "%s/n", mysql_error(conn));
exit(0);
}
res = mysql_use_result(conn);
/* output fields 1 and 2 of each row */
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s %s/n", row[1], row[2]);
mysql_close(conn);
}