int pc_getLvlProfession(int char_id, const char* profession)
{
char tmp_sql[65535];
static Sql* mmysql_handle3 = NULL;
char* data;
unsigned int nivelProfesion = 0;
//we now retain mmysql_handle3 to reuse it for next function call
//please remenber to free it on mapserv do_final to avoid memleak
if( mmysql_handle3 == NULL){
mmysql_handle3 = Sql_Malloc();
if( SQL_ERROR == Sql_Connect(mmysql_handle3, "user", "pass", "host", 3306, "database") )
{
ShowDebug("Error al intentar hacer un pc_getLvlProfession(1)");
exit(EXIT_FAILURE);
}
}
sprintf(tmp_sql, "SELECT c.`nivel` FROM `charprofesiones` WHERE `char_id` = %d LIMIT 1", char_id);
if ( SQL_ERROR == Sql_Query(mmysql_handle3, tmp_sql))
{
Sql_FreeResult(mmysql_handle3);
return nivelProfesion;
}
if( SQL_SUCCESS != Sql_NextRow(mmysql_handle3))
{
Sql_FreeResult(mmysql_handle3);
return nivelProfesion;
}
Sql_GetData(mmysql_handle3, 0, &data, NULL);
nivelProfesion = atoi(data);
Sql_FreeResult(mmysql_handle3);
return nivelProfesion;
}