SA-MP Forums Archive
mysql not connecting - 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 not connecting (/showthread.php?tid=455933)



mysql not connecting to the Database - Blademaster680 - 03.08.2013

Resolved
It wasnt inserting into the table when someone registers

I dont think mysql is connecting to the Database
It isnt logging anything except
Код:
[Sat Aug 03 16:43:09 2013] -------------------------
[Sat Aug 03 16:43:09 2013]      Logging Started
[Sat Aug 03 16:43:09 2013] -------------------------
[Sat Aug 03 16:47:41 2013] -------------------------
[Sat Aug 03 16:47:41 2013]       Logging Ended
[Sat Aug 03 16:47:41 2013] -------------------------
This is the code:
Код:
public OnGameModeInit()
{
	mysql_connect("Hostname", "Username", "Password", "Database");
	
	SetGameModeText("gamemode");
	AddPlayerClass(299, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	return 1;
}
Код:
stock SavePlayer(playerid)
{
	new query[126], pName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pName, sizeof(pName));
	
	GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
	
	format(query, sizeof(query), "UPDATE accounts SET Name = '%s', Password = '%s', PlayerX = '%f', PlayerY = '%f', PlayerZ = '%f' WHERE name = '%s'", pName, Player[playerid][Password], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], pName);
	mysql_query(query);
	printf("Player ID %d (%s)has been saved", playerid, pName);
}



Re: mysql not connecting - Sk1lleD - 03.08.2013

You must change
Код:
mysql_connect("Hostname", "Username", "Password", "Database");
With the host and database info like:
Код:
mysql_connect("127.0.0.1", "Username", "Password", "Database"); // This connect to the localhost server, and access to the DB called Database with Username , Password as credential
You can use phpMyAdmin and XAMPP to set a local server to host DB


Re: mysql not connecting - Zex Tan - 03.08.2013

Add the
pawn Код:
mysql_debug(1);
Put it in the OnGameModeInit. Start your server, and look at the Debug at your server files. You can check your errors there.


Re: mysql not connecting - Blademaster680 - 04.08.2013

I added the mysql_debug(1); and it stopped logging anything...

Its still not saving the playerdata...

Код:
enum PlayerStats {
	Name[126],
	Password[126],
	Float: Position[3],
}
Код:
public OnPlayerDisconnect(playerid, reason)
{
	SavePlayer(playerid);
	return 1;
}
Код:
stock SavePlayer(playerid)
{
	new query[126], pName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pName, sizeof(pName));
	
	GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
	
	format(query, sizeof(query), "UPDATE accounts SET Name = '%s', Password = '%s', PlayerX = '%f', PlayerY = '%f', PlayerZ = '%f' WHERE name = '%s'", pName, Player[playerid][Password], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], pName);
	mysql_query(query);
	printf("Player ID %d (%s)has been saved", playerid, pName);
}
I have got the database set up and the table's and structure right... But its not saving

In the database.. Should the Password and Name be a varchar or a Int?


Re: mysql not connecting - Sk1lleD - 04.08.2013

try with this:
pawn Код:
stock SavePlayer(playerid)
{
    new query[126], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
   
    GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);
   
    format(query, sizeof(query), "UPDATE `accounts` SET Name = '%s', Password = '%s', PlayerX = '%f', PlayerY = '%f', PlayerZ = '%f' WHERE `name` = '%s'", pName, Player[playerid][Password], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], pName);
    mysql_query(query);
    printf("Player ID %d (%s)has been saved", playerid, pName);
}



Re: mysql not connecting - Blademaster680 - 04.08.2013

Nope still nothing .
In the database.. Should the Password and Name be a varchar or a Int?

the whole code:
http://pastebin.com/FLatkTdd