StrickenKid's MYSQL Issue - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: StrickenKid's MYSQL Issue (
/showthread.php?tid=363159)
StrickenKid's MYSQL Issue -
SkyWinder - 26.07.2012
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
Re: StrickenKid's MYSQL Issue -
Benjo - 26.07.2012
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.
Re: StrickenKid's MYSQL Issue -
SkyWinder - 27.07.2012
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.
Re: StrickenKid's MYSQL Issue -
Benjo - 27.07.2012
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.
Re: StrickenKid's MYSQL Issue -
SkyWinder - 27.07.2012
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;
}