Max3D Posted July 20, 2008 Share Posted July 20, 2008 I'm having a few issues getting my script to connect to my mysql database on my localhost. what i basiclly want it to do is connect to the mysql database globally. so that i can use functions locally to insert, update data in tables on the database etc. but i use this function handler = mysql_connect("localhost", "script", "password", "script") -- Establish the connection if ( not handler ) then -- The connection failed outputDebugString("Unable to connect to the MySQL server") else mysql_close(handler) -- Close the connection end and it returns error. mysql_connect returned a value of nill please help, and any advice you can give me on using mysql commands to help script will be loved. thank you in advance Link to comment
Ace_Gambit Posted July 20, 2008 Share Posted July 20, 2008 Did you install the MTA-MySQL module? Link to comment
Max3D Posted July 20, 2008 Author Share Posted July 20, 2008 i sure did *Update Fixed, turns out their was a spelling mistake in the config file. but any mysql advice that you can give would be helpful. thank you Link to comment
Max3D Posted July 20, 2008 Author Share Posted July 20, 2008 New problem .. I i'm using the following registration function function RegisterPlayer(playerSource, commandName, _password) local name = mysql_escape_string(handler, getPlayerName(playerSource)) -- Escape the strings to avoid SQL-Injection local password = mysql_escape_string(handler, _password) local query = "INSERT INTO account SET name='" .. name .. "', password=MD5('" .. password .. "')" if (mysql_query(handler, query)) then outputChatBox("Account created successfuly with id #" .. mysql_insert_id(handler), playerSource) else outputChatBox("An error has occured when trying to create your account.", playerSource) end end addCommandHandler("reg", RegisterPlayer) when i run /reg in game it comes up with this error. [21:22:42] ERROR: ...server/mods/deathmatch/resources/myserver/script.lua:23: attempt to call global 'getPlayerName' (a nil value) thank you in advance Link to comment
Ace_Gambit Posted July 20, 2008 Share Posted July 20, 2008 You are using the client side equivalent of getClientName. Client: getPlayerName Server: getClientName Link to comment
robhol Posted July 21, 2008 Share Posted July 21, 2008 INSERT INTO doesn't work like that. Suppose you've got a table(userTable) with userID, Name and Pass. (in order) INSERT INTO userTable(userID,Name,Pass) VALUES(42,"JohnDoe","1234"); Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now