MySQL Question - 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 Question (
/showthread.php?tid=386308)
MySQL Question -
2KY - 20.10.2012
Am I doing this right, and could someone give me some advice as to what I could be doing better? I'm brand new to using MySQL in PAWN, so I'm having a pretty hard time adjusting.
pawn Код:
new
connectionHandle;
public OnGameModeInit()
{
mysql_debug( true );
connectionHandle = mysql_connect("localhost", "sky", "samp", "lol");
mysql_function_query( connectionHandle, "SELECT * FROM `mine`", true, "OnPlayerSelected", "");
SetGameModeText("Anarchy");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
forward OnPlayerSelected( );
public OnPlayerSelected( )
{
mysql_function_query( connectionHandle, "UPDATE `mine` SET `lol` = 1 WHERE `lol` = 16", false, "", "" );
return true;
}
From what I can understand, this query thing basically works like SetTimerEx, you pass the parameters then your callback picks them up and you do the rest of your things in there.. If someone could explain it in lamens terms, that'd be like.. perfect.
Re: MySQL Question -
ReneG - 20.10.2012
PHP код:
new var[2];
forward OnPlayerSelected( );
public OnPlayerSelected( )
{
new rows, fields;
cache_get_data( rows, fields ); // fetch how many results, and fields the query returned.
if( rows ) { // if there are rows
new content[ 20 ]; // new string to hold the values from the database
for( new row = 0; row < rows; row++ ) { // loop through all the rows, like looping through a file almost
cache_get_field_content( row, "Field1", content ); // get Field1 and store it into content
var[ 0 ] = strval( content ); // self explanatory
cache_get_field_content(row, "Field2", content); // get Field2 and store it into content
var[ 1 ] = strval( content ); // same thing
}
}
return true;
}