MYSQL *conn;
MYSQL_RES *result; MYSQL_ROW row;
int num_fields;
int i;
//for reconnect
#if MYSQL_VERSION_ID >= 50013
my_bool reconnect;//my_bool = char
#endif
conn = mysql_init(NULL);
#if MYSQL_VERSION_ID >= 50013
reconnect = 1;
//set re-conn to true. could use ping to reconn
if (mysql_options(conn, MYSQL_OPT_RECONNECT, &reconnect) != 0) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
#endif
if (conn == NULL) {
//printf("%s\n",__LINE__);
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
if (mysql_real_connect(conn, "localhost", "root", "", "online_stat", 0, NULL, 0) == NULL) {
//printf("%s\n",__LINE__);
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
/* mysql_query(conn, "SELECT * FROM daily_online_stat");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
for(i = 0; i < num_fields; i++)
{
printf("%s ", row[i] ? row[i] : "NULL");
}
printf("\n");
}
*/
char strSql[1000];
bzero(strDate, 20);
bzero(strSql, 1000);
//TODO:TEST
getDate(strDate);
printf("%s", strDate);
strPeak = "999";
strWebId = "Adios";
strTotalLogin = "12345";
sprintf(strSql, "insert into daily_online_stat values ('NULL', '%s', '%s', '%s', '%s');", strDate, strPeak.c_str(), strTotalLogin.c_str(), strWebId.c_str());
printf("%s\n", strSql);
mysql_query(conn, strSql);
//mysql_free_result(result);
mysql_close(conn);