SA-MP Forums Archive
mysql_fetch_row causing server crash - 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: mysql_fetch_row causing server crash (/showthread.php?tid=547014)



mysql_fetch_row causing server crash - Jonesy96 - 19.11.2014

Hi all, please review the code below. For some reason, whenever I try to run this function and there is more than one charge to be displayed using mysql_fetch_row, the server just instantly crashes. The server_log.txt says nothing about it and the mysql log says the following:

Код:
[Wed Nov 19 22:05:20 2014] Function: mysql_query executed: "SELECT * FROM `mdc_charges` WHERE `suspect_playerdata_pid`=19 AND `arrest_id` IS NULL;" with result: "0".
[Wed Nov 19 22:05:20 2014] Function: mysql_store_result executed with result: "1"
[Wed Nov 19 22:05:20 2014] Function: mysql_fetch_row executed with result: "2|19|19|Evading a Peace Officer|NULL|2014-11-19 21:46:52".
[Wed Nov 19 22:05:20 2014] Function: mysql_fetch_field executed.
Код:
public mdcDisplayPerson(playerid,playername[]){
	new string[900];
	new Query[900];
	new pid;
	new username[34];
	new charge[60];
	
	format(Query, sizeof(Query), "SELECT * FROM `playerdata` WHERE `username`='%s'", playername);
    mysql_query(Query);
    mysql_store_result();
	if(mysql_num_rows() == 1){
	    mysql_fetch_int("pid", pid); //Get player db ID
	    mysql_fetch_field("username", username); //Get player name
	    mysql_free_result();
	    format(string, sizeof(string), "Full Name: %s", username);
		
		//Listing charges
		format(Query, sizeof(Query), "SELECT * FROM `mdc_charges` WHERE `suspect_playerdata_pid`=%d AND `arrest_id` IS NULL;", pid);
	    mysql_query(Query);
	    mysql_store_result();
	    new count = 0;
	    while(mysql_fetch_row(Query)){
	        mysql_fetch_field("charge", charge);
            if(count == 0){
                format(string, sizeof(string), "%s\n\nACTIVE CHARGE(s):\n\n %s", string, charge);
			}else{
			    format(string, sizeof(string), "%s\n%s", string, charge);
			}
			count++;
		}
		mysql_free_result();
		
		
		ShowPlayerDialog(playerid, DIALOG_PD_MDC_SEARCHNAME_SUCCESS, DIALOG_STYLE_MSGBOX, "Persons Search", string, "Close", "");
	}else{
		//No user with name
		ShowPlayerDialog(playerid, DIALOG_PD_MDC_SEARCHNAME_ERROR, DIALOG_STYLE_MSGBOX, "Persons Search", "No persons found", "Close", "");
	}
	return 1;
}
Any help would be much appreciated!


Re : mysql_fetch_row causing server crash - Dutheil - 19.11.2014

I think your problem is here (after "NULL") :

Код:
ormat(Query, sizeof(Query), "SELECT * FROM `mdc_charges` WHERE `suspect_playerdata_pid`=%d AND `arrest_id` IS NULL;", pid);



Re: mysql_fetch_row causing server crash - Jonesy96 - 19.11.2014

Tried and tested, made no difference.


Re : mysql_fetch_row causing server crash - Dutheil - 19.11.2014

I've never used your mysql version, but I think that's because you have several connections in same time.


Re: Re : mysql_fetch_row causing server crash - Jonesy96 - 19.11.2014

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
I've never used your mysql version, but I think that's because you have several connections in same time.
Sorry but I don't understand what you mean there. I assume you're not talking about connections because there is one connection and that is to the database...


Re : mysql_fetch_row causing server crash - Dutheil - 19.11.2014

Honestly, don't adventure with that mysql version.
Take the latest version : MySQL R39-2.

When you understand it, it's very easy, fast and less cumbersome.
If you need help to understand how that version works, don't hesitate to post.


Re: mysql_fetch_row causing server crash - Jonesy96 - 20.11.2014

I don't particularly wish to do that as my script is very much developed now. There must be an issue with my code above because I've used the same technique to loop through results several times in my script and had no issue.

Any ideas?