MySQL Help

I’m trying to make it so when the player joins the server, it checks if it finds their steam id… and if it doesnt, then it creates it…

I’m having some problems.

local DATABASE_PORT = 3306
local DATABASE_NAME = “test”
local DATABASE_USERNAME = “TheUsername”
local DATABASE_PASSWORD = “ThePassword”

function connectToDatabase()
databaseObject.onConnected = function() print(“Database linked!”) end
databaseObject.onConnectionFailed = function() print(“Failed to connect to the database.”) end


function ConnectToServer( ply )

hook.Add(“PlayerInitialSpawn”, “PlayerInitialSpawn”, ConnectToServer)[/lua]

I have the connecting working, but how do I do the function for when they join?

You probably want to do a select query, if the select query returns nothing then run a insert query, else update the information with a update query.

You also should do the connection when the player spawns if one is not currently active because your DB will probably timeout and you cannot connect to your DB without a player on the server.

Can you show me an example?

If you want, I can post some snippets of the code from my servers, but it will probably have alot of unrelated stuff and would be hard for you to directly edit it.

What exactly do you need an example of?

How to check if something is created in the MySQL, and if it isn’t then create it for like a SteamID.

You run a query like in the example where you download mysqloo, and then you can google a select and insert query.

If you still need help with this view my latest MYSQL thread in this section, my first snippet should work for you.