MySQL Help!
#1

Im a sort of beginner at MySQL,

Anyway im using StrickenKid's MySQL plugin,
I have this ( My friend gave me it ) to for a register:

pawn Код:
CMD:test1(playerid, params[])
{
    new string[256];
    format(string,sizeof(string),"INSERT INTO `users` (`username`, `password`) VALUES ('%s', '%s')", GetName(playerid), params);
    mysql_query(string);
    return 1;
}
And ingame when i type that command, It sends this to my server console:

Quote:
Originally Posted by Server Console
MySQL Error <0>: Function 'mysql_query' called when not connected to any database, Access denied for user 'root'@'password' <using password: YES>
But when i loaded the FS it successfully connected to mysql
Reply
#2

Well Torran, i am stumped.....shit i used to know SQL too, but then i starting scripting roleplay's and i stoped using SQL and now i suck at it. Sorry i couldn't help

:/
Reply
#3

Quote:
Originally Posted by Steven82
Well Torran, i am stumped.....shit i used to know SQL too, but then i starting scripting roleplay's and i stoped using SQL and now i suck at it. Sorry i couldn't help

:/
Lol? Anyway if anyone knows why it says it successfully connects upon gamemode init and then when someone tries to register it says it cannot connect
Reply
#4

Ask in plugin's topic. And read some articles about SQL injection because your command is just made for that.
Reply
#5

before running the query check if you are still connected to the database.

Код:
CMD:test1(playerid, params[])
{
	if (mysql_ping())
	{
		new string[256];
		format(string,sizeof(string),"INSERT INTO `users` (`username`, `password`) VALUES ('%s', '%s')", GetName(playerid), params);
		mysql_query(string);

		SendClientMessage(playerid, 0xFFFFFFFF, "Connected and query success!");
	}
	else
	{
	  SendClientMessage(playerid, 0xFFFFFFFF, "You are not connected to the database!");
	}
	return 1;
}
Reply
#6

This is very confusing as i tried again and it says it connects successfully and then when i type the command it says it cant do mysql_whatever because im not connected to a database!
Reply
#7

You can quickly fix it by using functions with each query that will check if you are connected still.

Код:
stock MySQL()
{
	if (!mysql_ping())
	{
	  print("Reconnecting to database.");
	  mysql_connect(hostname, username, database, password); 
	  MySQL(); // this will just execute the function to check again.
	}
}
Код:
CMD:test1(playerid, params[])
{
	MySQL();
	new string[256];
	format(string,sizeof(string),"INSERT INTO `users` (`username`, `password`) VALUES ('%s', '%s')", GetName(playerid), params);
	mysql_query(string);
	return 1;
}
Reply
#8

Quote:
Originally Posted by Steven82
Well Torran, i am stumped.....shit i used to know SQL too, but then i starting scripting roleplay's and i stoped using SQL and now i suck at it. Sorry i couldn't help

:/
Omg you such a spamer i been seen many post about you know Php html and now SQL and presume your a god at it but cant help at all?
you earned your report
Reply
#9

Ok so i finally got the hang of MySQL, After all this i ended up using Adrenaline DJ's plugin/include :P
Reply
#10

Quote:
Originally Posted by Joe Torran C
Ok so i finally got the hang of MySQL, After all this i ended up using Adrenaline DJ's plugin/include :P
You fell really low.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)