I am trying to connect my mud to my sql server to update statistics which are being displayed on our website. I got the code working from a snippet, and everything compiles fine. However it keeps loosing the connection before its able to perform the queries. Can anyone tell me whats wrong with the following.
#define MYSQL_SERVER '127.0.0.1'
#define MYSQL_DB 'thedragonball'
#define MYSQL_USER '****'
#define MYSQL_PWD '******'
int stats_update_mkills(CHAR_DATA *attacker)
{
MYSQL *hnd;
char sql[1000];
if ( (hnd = mysql_init(NULL)) == NULL ) {
return -1;
}
if ( mysql_real_connect(hnd,MYSQL_SERVER,MYSQL_USER,MYSQL_PWD,MYSQL_DB,1210,NULL,0) == NULL ) {
char buf[MAX_STRING_LENGTH];
sprintf( buf, 'Stats_Update_Mkills: Error: %s', mysql_error(hnd) );
monitor_chan( buf, MONITOR_GEN_IMM, LEVEL_IMMORTAL );
mysql_close(hnd);
return -2;
}
sprintf(sql,'update mud_player_stats set mkills = %d where player = '%s'', attacker->pcdata->mkills, attacker->name );
if ( mysql_real_query(hnd, sql, strlen(sql)) != 0 ) {
monitor_chan( 'Stats_Update_Mkills: stage 2 failed', MONITOR_GEN_IMM, LEVEL_IMMORTAL );
mysql_close(hnd);
return -3;
}
if ( mysql_affected_rows(hnd) == 0 ) {
sprintf(sql,'insert into mud_player_stats values( '%s', 0, %d, 0, 0, 0, 0 )', attacker->name, attacker->pcdata->mkills );
if ( mysql_real_query(hnd, sql, strlen(sql)) != 0 ) {
monitor_chan( 'Stats_Update_Mkills: stage 3 failed', MONITOR_GEN_IMM, LEVEL_IMMORTAL );
mysql_close(hnd);
return -4;
}
}
mysql_close(hnd);
return 0;
}
This is what I keep getting: Error: Lost connection to MySQL server during query |