SQL Evolvemod

[lua]local DATABASE_HOST = “"
local DATABASE_PORT = "

local DATABASE_NAME = “"
local DATABASE_USERNAME = "

local DATABASE_PASSWORD = “*”

function sql_value_vipoints ( ply )
unique_id = sql.QueryValue(“SELECT unique_id FROM vipointstable WHERE unique_id = '”…steamID…"’")
VIPoints = sql.QueryValue(“SELECT VIPoints FROM vipointstable WHERE unique_id = '”…steamID…"’")
ply:SetNWString(“unique_id”, unique_id)
ply:SetNWInt(“VIPoints”, money)
end
function sql_evolveranks ( ply )
unique_id = sql.QueryValue(“SELECT unique_id FROM evolveranks WHERE unique_id = '”…steamID…"’")
name = sql.QueryValue(“SELECT name FROM evolveranks WHERE unique_id = '”…steamID…"’")
rank = sql.QueryValue(“SELECT rank FROM evolveranks WHERE unique_id = '”…steamID…"’")
ply:SetNWString(“unique_id”, unique_id)
ply:SetNWString(“name”, name)
ply:SetNWInt(“rank”, rank )
end

function saveStat ( ply )
VIPoints = ply:GetNWInt(“VIPoints”)
unique_id = ply:GetNWString(“SteamID”)
sql.Query(“UPDATE player_info SET VIPoints = “…VIPoints…” WHERE unique_id = '”…unique_id…"’)
ply:ChatPrint(“Stats updated !”)
end

function tables_exist()

	if (sql.TableExists("vipointstable") && sql.TableExists("evolveranks") then
			Msg("Both tables already exist!")
	else
			if (!sql.TableExists("vipointstable"))
					query = "CREATE TABLE vipointstable ( unique_id varchar(255), VIPoints int, admins )"
					result = sql.Query(query)
					if sql.TableExists("vipointstable")) then
						Msg("vipointstable has been created! 

")
else
Msg("vipointstable failed to query!
")
Msg( sql.LastError( result ) … "
" )
end
end

			if (!sql.TableExists("evolverank")) then
					query = "CREATE TABLE evolveranks ( unique_id varchar(255), name, rank ) "
					result = sql.Query( query )
					if sql.TableExists("evolveranks")) then
							Msg("Evolveranks table has been created! 

")
else
Msg("Evolveranks failed to query!
")
Msg( sql.LastError( result ) … "
")

					end

			end
	end

end

function new_player( SteamID, ply)

			steamID = SteamID
			sql.Query( "INSERT INTO vipointsable( `unique_id`, `VIPoints`)VALUES ('"..steamID.."', '100')" ) 
			result = sql.Query( "SELECT unique_id, VIPoints FROM vipointstable WHERE unique_id = '"..steamID.."'" )
			if (result) then
					
					sql.Query( "INSERT INTO evolveadmins (`unique_id`, `name`, `rank` )VALUES ('"..steamID.."', '1', '1', '1')" )
					result = sql.Query( "SELECT unique_id, name, rank FROM evolveranks WHERE unique_id = '"..steamID.."'" )
					if (result) then
							Msg("account created !

")
sql_value_vipoints( ply )
sql_value_evolveranks( ply )
else
Msg("Failed to create evolveranks !
")
end
else
Msg("Failed to create vipoints !
")
end
end

function player_exists( ply )
steamID = ply:GetNWString(“SteamID”)

	result = sql.Query("SELECT unique_id, VIPoints FROM vipoints WHERE unique_id = '"..steamid"'")
	if (result) then
					sql_value_vipoints( ply )
					sql_value_evolveranks( ply )
	else
			new_player( steamID, ply )
	end

end

function Initialize()
tables_exist()
end

function PlayerInitialSpawn( ply )

	timer.Create("Steam_id_delay", 1, 1, function()
			SteamID = ply:SteamID()
			ply:SetNWString("SteamID", SteamID)
			timer.Create("SaveStat", 10, 0, function() saveStat( ply ) end)
			player_exists( ply )
	end)	

end

function Set_Player_Status ( ply )

rank = sql.QueryValue("SELECT rank FROM evolveranks WHERE unique_id = '"..steamID.."'")

if rank == "respected" then ply:EV_SetRank ( "respected" )
if rank == "donator" then ply:EV_SetRank( "donator" )
if rank == "admin" then ply:EV_SetRank( "admin" )
if rank == "superadmin" then ply:EV_SetRank( "superadmin" )
if rank == "owner" then ply:EV_SetRank( "owner" )

end

end

hook.Add( “PlayerInitialSpawn”, “PlayerInitialSpawn”, PlayerInitialSpawn )
hook.Add( “Initialize”, “Initialize”, Initialize )

function connectToDatabase()
local databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
databaseObject.onConnected = afterConnected
databaseObject:connect()
end

connectToDatabase()[/lua]

The stars is just to cover the server details, the database connections are correct. ( I tried via HeidiSQL ) The problem is. It’s not creating the tables ;/ Any ideas? It is currently placed in lua/autorun/server

[editline]10:24PM[/editline]

[lua]function sql_evolveranks[/lua]

small little fix… It’s supposed to be sql_value_evolveranks

Still not working…

SQL module installed? yournot requireing it in conde , And i think you might have to manualy create the tables your self

He’s using SQLite, it comes with GMod. Notice the sql.Query

[editline]10:41AM[/editline]

Hey wait, are you trying to use MySQL or SQLite??

SQLite

It is required in my code… I found out I was missing it, still not working though.

mayby give us an erorr?

I can’t give you an error, when there isnt an error.

well explain in depth what isnt working

Well… The tables arent being created. That’s my issue.

Why not create them manually?

This is what I would do if I had tmysql I don’t have mysqloo but should be simple to change.
[lua]
tmysql.query( “CREATE TABLE IF NOT EXISTS CREATE TABLE vipointstable ( unique_id varchar(255), VIPoints int, admins )” )

tmysql.query( "CREATE TABLE IF NOT EXISTS CREATE TABLE evolveranks ( unique_id varchar(255), name, rank ) " )
[/lua]
Place near the top of the file.