Jump to content

MYSQL connect problem


Max3D

Recommended Posts

Posted

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

Posted

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

Posted

New problem :D..

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

Posted

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");

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...