#define SOCKET int
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
int main(int argc, char* argv[])
{
// {
int nRet = 1;
MYSQL conn;
int query_stat;
mysql_init(&conn);
// DB 연결
MYSQL *connection = mysql_real_connect(&conn, "localhost",
"user_id", "user_pass", "my_db", 3306, (char *)NULL, 0);
if (NULL == connection) {
fprintf(stderr, "Mysql connection error : %s", mysql_error(&conn));
goto exit_here;
}
MYSQL_RES *sql_result;
MYSQL_ROW sql_row;
query_stat = mysql_query(connection, "select field1, field2 from my_tb");
if (0 != query_stat) {
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
goto exit_here;
}
sql_result = mysql_store_result(connection);
while ( NULL != (sql_row = mysql_fetch_row(sql_result)) ) {
printf("field1(%s), field2(%s)\n",sql_row[0], sql_row[1]);
}
mysql_free_result(sql_result);
nRet = 0;
exit_here:
if (NULL != connection)
mysql_close(connection);
// }
// printf("Hello World!\n");
return nRet;
// return 0;
}