-
Apr 11th, 2016, 11:23 AM
#1
Thread Starter
Member
[HELP] Reading MySQL database tables
Hello. So I have this C++ code:
Code:
void mysql_do_ds_awards()
{
#ifdef USE_MYSQL
char sql_cmd[5000];
MYSQL_RES *res;
MYSQL_ROW row;
unsigned int num_fields;
unsigned int i;
char *server = "localhost";
char *db_user = MYSQL_USER;
char *db_password = MYSQL_PASSWORD;
char *database = "game_pay_db";
MYSQL *my_sql_here_conn;
//make connection
while(mysql_mutex)
uni_pause(100);
mysql_mutex = 1;
my_sql_here_conn = mysql_init(NULL);
if(!my_sql_here_conn)
{
printf("mysql: cannot init mysql for ds awards\n");
mysql_mutex = 0;
return;
}
if(mysql_real_connect(my_sql_here_conn, server, db_user, db_password, database, 0, NULL, CLIENT_FOUND_ROWS))
{
printf("mysql: connection established for ds awards\n");
}
else
{
printf("mysql: cannot connect ds awards: %s\n", mysql_error(my_sql_here_conn));
mysql_close(my_sql_here_conn);
mysql_mutex = 0;
return;
}
sprintf(sql_cmd, "SELECT * FROM payout_entry WHERE was_paid = 2");
if(mysql_query(my_sql_here_conn, sql_cmd))
{
printf("mysql: selection error: %s\n", mysql_error(my_sql_here_conn));
mysql_close(my_sql_here_conn);
mysql_mutex = 0;
return;
}
res=mysql_store_result(my_sql_here_conn); /* Download result from server */
num_fields = mysql_num_fields(res);
while ((row = mysql_fetch_row(res)))
{
unsigned long *lengths;
int i;
lengths = mysql_fetch_lengths(res);
char username[2][500];
int ds_tobe[2], tabID;
tabID = atoi(row[0]);
strcpy(username[0], row[1]);
ds_tobe[0] = atoi(row[2]);
strcpy(username[1], row[3]);
ds_tobe[1] = atoi(row[4]);
award_user_ds(username[0], ds_tobe[0]);
award_user_ds(username[1], ds_tobe[1]);
//mysql_query("UPDATE payout_entry SET was_paid='1' WHERE tabID='" . $the_id . "'");
sprintf(sql_cmd, "UPDATE payout_entry SET was_paid='1' WHERE tabID='%d'", tabID);
if(mysql_query(my_sql_here_conn, sql_cmd))
{
printf("mysql: pay marking error: %s\n", mysql_error(my_sql_here_conn));
continue;
}
}
printf("mysql: connection closed for ds awards\n");
mysql_free_result(res); /* Release memory used to store results. */
mysql_close(my_sql_here_conn);
mysql_mutex = 0;
#endif
}
void mysql_do_mfc_awards()
{
#ifdef USE_MYSQL
char sql_cmd[5000];
MYSQL_RES *res;
MYSQL_ROW row;
unsigned int num_fields;
unsigned int i;
char *server = "localhost";
char *db_user = MYSQL_USER;
char *db_password = MYSQL_PASSWORD;
char *database = "game_affiliate_db";
MYSQL *my_sql_here_conn;
//make connection
while(mysql_mutex)
uni_pause(100);
mysql_mutex = 1;
my_sql_here_conn = mysql_init(NULL);
if(!my_sql_here_conn)
{
printf("mysql: cannot init mysql for mfc awards\n");
mysql_mutex = 0;
return;
}
if(mysql_real_connect(my_sql_here_conn, server, db_user, db_password, database, 0, NULL, CLIENT_FOUND_ROWS))
{
printf("mysql: connection established for mfc awards\n");
}
else
{
printf("mysql: cannot connect mfc awards: %s\n", mysql_error(my_sql_here_conn));
mysql_close(my_sql_here_conn);
mysql_mutex = 0;
return;
}
sprintf(sql_cmd, "SELECT * FROM affiliate_user WHERE aff_exp > 0");
if(mysql_query(my_sql_here_conn, sql_cmd))
{
printf("mysql: selection error: %s\n", mysql_error(my_sql_here_conn));
mysql_close(my_sql_here_conn);
mysql_mutex = 0;
return;
}
res=mysql_store_result(my_sql_here_conn); /* Download result from server */
num_fields = mysql_num_fields(res);
while ((row = mysql_fetch_row(res)))
{
unsigned long *lengths;
int i;
lengths = mysql_fetch_lengths(res);
char their_username[500];
int exp_tobe, money_tobe, tabID;
tabID = atoi(row[0]);
strcpy(their_username, row[4]);
exp_tobe = atoi(row[5]);
money_tobe = atoi(row[6]);
user_award_mfc(their_username, exp_tobe, money_tobe);
//mysql_query("UPDATE affiliate_user SET aff_exp='0', aff_money='0' WHERE tabID='" . $the_id . "'");
sprintf(sql_cmd, "UPDATE affiliate_user SET aff_exp='0', aff_money='0' WHERE tabID='%d'", tabID);
if(mysql_query(my_sql_here_conn, sql_cmd))
{
printf("mysql: aff clearing error: %s\n", mysql_error(my_sql_here_conn));
continue;
}
}
printf("mysql: connection closed for mfc awards\n");
mysql_free_result(res); /* Release memory used to store results. */
mysql_close(my_sql_here_conn);
mysql_mutex = 0;
#endif
}
I already have made the two MySQL databases game_pay_db and game_affiliate_db.
Now I don't really know MySQL and I don't know what tables I have to make inside these databases in order to make this code work.
When I make a table "payout_entry" in the database, it shows me a bunch of rows to fill in name, type, length, etc ... I think the C++ code shows exactly what tables and rows have to be created in the database, I just don't completely understand it, so...
Can I get a little help here, please ? Thanks.
Last edited by Edelweise; Apr 11th, 2016 at 11:28 AM.
-
Apr 12th, 2016, 08:06 AM
#2
Thread Starter
Member
Re: [HELP] Reading MySQL database tables
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|