Jump to content

MYSQL connect problem


Max3D

Recommended Posts

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

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

Link to comment

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...