SA-MP Forums Archive
MySQL Update - 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 Update (/showthread.php?tid=621379)



MySQL Update - Banditul18 - 10.11.2016

Hello guys i have a question about mysql update from r6(i think) to r41
I have this 2 things:
Код:
public MySQLCheckCar(carname[])
{
	new query[128],escstr[MAX_PLAYER_NAME];
	mysql_real_escape_string(carname, escstr);
	format(query, sizeof(query), "SELECT `ID` FROM stock WHERE `Car` = '%s'", escstr);
	mysql_query(SQL,query);
	mysql_store_result();
	if (mysql_num_rows()==0)
	{
	    mysql_free_result();
		return 0;
	}
	else
	{
		new strid[32],intid;
		mysql_fetch_row(strid);
		intid = strval(strid);
	    mysql_free_result();
		return intid;
	}
}
Код:
public MySQLCheckCar(carname[])
{
	new query[64],intid;
	mysql_format(query, sizeof(query), "SELECT `ID` FROM stock WHERE `Car` = '%e'", carname);
	mysql_tquery(SQL,query, "", "");
	if(cache_num_rows() > 0)
	{
		cache_get_value_name_int(0, "ID",intid);
		return intid;
	}
}
They do same thing? Or i need to call mysql querry first and then get cache from it?(second one)
The function is called everytime an admin set a car to the stock....
I want to learn to update from that old functions to new one, for me of course, you don't know when you need....


Re: MySQL Update - dicknyson - 10.11.2016

You need to call a callback when the query has finished running. Do this with the mysql_tquery function, for example
Код:
mysql_tquery(SQL,query, "CallBack");
and then

Код:
forward CallBack();
public CallBack()
{
     //fetch data here



Re: MySQL Update - Banditul18 - 10.11.2016

Oh...Thanks, i was not sure if i need to call the callback from tquery or not....Thanks again