StrickenKid's MYSQL Issue
#1

Hello,

The scripts working fine and all.

About 8 months back when i tested this script, it worked perfect.

Now i updated all the plugins and stuff and when i try it again.

Soon as i use mysql_fetch_field

The server crashes.

No idea why.

Please help me.

Thanks
Reply
#2

I'd suggest putting mysql_debug(1) at the top of OnGameModeInit / OnFilterScriptInit. This will log mysql activity into mysql_log.txt, allowing you to get a bit of further analysis.

As you say your server is crashing, I would check the array size of the variable that you are storing the result of mysql_fetch_field into. Trying to save a string that is too long for a variable is often the cause of my crashes relating to mysql.
Reply
#3

This is the mysql log for when it crashes

Код:
[Fri Jul 27 21:56:33 2012] Function: mysql_query (threaded) executed: "SELECT * FROM `bans` WHERE (`ip` = '127.0.0.1') OR (`username` = 'Neal_Caffery')" with result: "0".
[Fri Jul 27 21:56:33 2012] Function: mysql_query executed: "SELECT * FROM `bans` WHERE (`ip` = '127.0.0.1') OR (`username` = 'Neal_Caffery')" with result: "0".
[Fri Jul 27 21:56:34 2012] Function: mysql_store_result executed with result: "1"
[Fri Jul 27 21:56:34 2012] Function: mysql_num_rows executed with result: "".
[Fri Jul 27 21:56:34 2012] Function: mysql_fetch_field executed.
Reply
#4

After executing your SELECT query and storing the result, you need to do a check to see if there were any results, which can be done as follows:
pawn Код:
mysql_query(yourquerystring);
mysql_store_result();

if(mysql_num_rows())
{
    // wahey, resultttt! fetch field(s) now or w/e!
}else{
    // no results found :-(
}
I believe trying to fetch a field of nil result is the reason for your mysql crash.
Reply
#5

ok here is my script

Код:
			mysql_store_result();
			new num_rows = mysql_num_rows();
			printf("This is the Amount of Num Rows : %d", num_rows);
			if(num_rows > 0)
			{
				//Match found - Remove Player
				new bannedname[24];
				mysql_fetch_field("username", bannedname);
				new adminname[24];
				mysql_fetch_field("adminname", adminname);
				new reason[128];
				mysql_fetch_field("reason", reason);
				new string[128];
\				format(string, sizeof(string), "You are banned from this server under the name %s by Admin %s for %s", bannedname, adminname, reason);
				SendClientMessage(spareid, COLOR_CYAN, string);
				Kick(spareid);
				mysql_free_result();
				return 1;
			}
			else
			{
			       print("No Results Found");
				// Player is not banned
				mysql_free_result();
				return 1;
			}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)