SA-MP Forums Archive
Mysql Select 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: Mysql Select issue (/showthread.php?tid=611131)



Mysql Select issue - Golimad - 02.07.2016

hello,

I have a filterscript, whitelist sort of way, I have a database table structured this way:

PRIMARY KEY - VARCHAR(32) - VARCHAR(32)
ID (int 11) - Player - IP

when a player joins the server, the filterscript must check the table if the playername is in there, if it's not, kick the player;

the issue is that, the table is empty with no data, but when player joins with whatever name, it doesn't kick him and says that he is on the database.

Here is some code :
Код:
CheckState(playerid)
{
	
	if(Enabled) //
	{
		CheckMySQL();
		new string[128], plrIP[16];
	    GetPlayerIp(playerid, plrIP, sizeof(plrIP));


		format(string, sizeof(string), "SELECT * FROM acplayers WHERE Player = '%s'", GetName(playerid));
		mysql_query(string);
		mysql_store_result();
		
		if(!mysql_num_rows()) // Kick him + Telling him to be in whitelist
		{
			// this line should be triggered cuz there is no player on table for now.. but it doesn't. it goes to the else statement.
		    Connected[playerid] = false;
		    KickInTime(playerid, 1);
	 	}
		else 
		{
		    mysql_free_result();
			// check if whitelisted ip is ok
			format(string, sizeof(string), "SELECT * FROM acplayers WHERE Player = '%s' AND IP = '%s'", GetName(playerid), plrIP);
			mysql_query(string);
			mysql_store_result();
			if(!mysql_num_rows()) // Kick him if not.
			{
			    Connected[playerid] = false;
		    	KickInTime(playerid, 2);
	 		}
	 		else
	 		{
				new row[128];
				new field[4][64];
				mysql_fetch_row_format(row, "|");
				explode(row, field, "|");
				mysql_free_result();
				format(ACPlayers[playerid][PlayerIP], 16, "%s", field[1]); // Address IPs
    			SendClientMessage(playerid, -1, ACPlayers[playerid][PlayerIP]); // This prints nothing "";
			}
		}
		mysql_free_result();
	}
    
}
thank you


Re: Mysql Select issue - Golimad - 02.07.2016

More details : mysql_log says I can't connect to root@localhost

database info:
127.0.0.1 root root dbnameexp

Any idea why it's not leting me in my localhost db? // I'm able to connect to it on a little application in C/C++ with working queries.


Re: Mysql Select issue - Golimad - 02.07.2016

sorry for reposting, edit didn't wanna work ..

mysql_log:

[21:05:29] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "root", password: "****", port: 3306, autoreconnect: true
[21:05:29] [DEBUG] CMySQLHandle::Create - creating new connection..
[21:05:29] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[21:05:29] [DEBUG] CMySQLHandle::Create - connection created with ID = 1
[21:05:29] [DEBUG] mysql_errno - connection: 1
[21:05:29] [DEBUG] mysql_query - connection: 1, query: "INSERT INTO `acplayers` (Player, IP) VALUES('TEST', '1243')"
[21:05:29] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[21:05:29] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[21:05:29] [DEBUG] CMySQLConnection:isconnect - connection was closed
[21:05:29] [DEBUG] CMySQLQuery::~CMySQLQuery() - deconstructor called


Re: Mysql Select issue - Golimad - 02.07.2016

SOLVED!

I was doing mysql_connect(host, user, pass, name) when it should have been mysql_connect(host, user, name, pass);
i was following standard format but i didn't know better.. thanks anyway