MySQL Problems

I am using this version

Well im trying to get the steamid from my databae and connect to it in garrys mod so that when you first spawn it will connect to the data base query the table and search all the steam id’s in there to find your steam id and if it does then it will add you to the VIP team because you signed up at the site.

But here’m my problem… When i join the game i will get a bunch of these errors…


"Too many vertex format changes in frame, whole world not rendered"

And all the players including those not found in the data base will have no team and no weapons on spawn…

here is the database.lua code
[lua]

require(“mysqloo”)
include(‘init.lua’)

local DATABASE_HOST = “”
local DATABASE_PORT = 80
local DATABASE_NAME = “”
local DATABASE_USERNAME = “”
local DATABASE_PASSWORD = “”

function printQuery(query)
PrintTable(query:getData())
end

function afterConnected(database)
local query1 = database:query(“SELECT steamid FROM srp WHERE steamid=’”…tostring(ply:SteamID())…"’)")
query1.onData = function(Q,D) print(“Q1”) PrintTable(D) end
query1.onSuccess = printQuery
query1.onError = function(Q,E) print(“Q1”) print(E) end
query1:start()

if(query1 == false) then  
        Msg("Account doesn't exist

")
ply:PrintMessage( HUD_PRINTTALK, "SRP:Welcome Guest! " … ply:Nick() )
sb_team1( ply )
else
ply:PrintMessage( HUD_PRINTTALK, “SRP:Welcome " … ply:Nick() … " You are a VIP Member!” )
sb_team3( ply )
end
end

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

connectToDatabase()

[/lua]

And on initial spawn which is located in init.lua it looks like this…

[lua]function GM:PlayerInitialSpawn( ply )
self.BaseClass:PlayerInitialSpawn( ply )

    local cash = ply:GetPData("cash")
    //local BackPack = {Code = 1, PropModel = "models/props_junk/watermelon01.mdl", Name = "Melon"}
    //local encodedData = glon.encode(BackPack)
    //ile.Write("items.txt", encodedData)

    if cash == nil then
        ply:SetPData("cash", STARTMONEY)
        ply:Money_Set(STARTMONEY)
    else
    ply:Money_Set(cash)
    end
    if ply:IsAdmin() then
            sb_team2( ply )
            ply:PrintMessage( HUD_PRINTTALK, "SRP:Welcome Admin! " .. ply:Nick() )
    else // If he isn't admin then,
    afterConnected(database)
    end

end

[/lua]

So can someone please help me :confused: Thank you

“Too many vertex format changes in frame, whole world not rendered” has nothing to do with it.

Then why does it show up everytime i try using the database.lua…

But do you know why the codes not working?

Did you setup a database on a mysql compatable server? I see above the fields are blank.

It’s talking about the map not your script, addon, gamemode. It’s refering to the corners within the map.

Either on a remote server or locally (using XAMPP or similar). Lets hope he didn’t want to use sqlOO with sqlite :downs:.

Im using the http://www.000webhost.com/ free service which has mysql and phpmyadmin. Yes i created a database and the table as well. I have all the fields place in (I didnt provide the user name and so on information because i don’t want other people to know it <_<) But for some reason it will not work…

Does the host allow remotesql?

ahh crap it is haha, anyone know of a free service that allows it XD

And other then that the code i posted should work right?

No, you need to escape your strings for correct usage in the SQL.

sql.SQLStr

Check it on the wiki.

require(“mysqloo”)

include(‘init.lua’)

local DATABASE_HOST = “”
local DATABASE_PORT = 80
local DATABASE_NAME = “”
local DATABASE_USERNAME = “”
local DATABASE_PASSWORD = “”

function printQuery(query)
PrintTable(query:getData())
end

function afterConnected(database)
local query1 = database:query("SELECT steamid FROM srp WHERE steamid = "… sql.SQLStr( steamid )
sql.QueryValue( query1 )
query1.onData = function(Q,D) print(“Q1”) PrintTable(D) end
query1.onSuccess = printQuery
query1.onError = function(Q,E) print(“Q1”) print(E) end
query1:start()

if(query1 == false) then  
        Msg("Account doesn't exist

")
ply:PrintMessage( HUD_PRINTTALK, "SRP:Welcome Guest! " … ply:Nick() )
sb_team1( ply )
else
ply:PrintMessage( HUD_PRINTTALK, “SRP:Welcome " … ply:Nick() … " You are a VIP Member!” )
sb_team3( ply )
end
end

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

connectToDatabase()
Like so?

I also edited the file abit, after doing some more research. I came up with this.

database.lua
[lua]
require(“mysqloo”)

include(‘init.lua’)

local DATABASE_HOST = “.”
local DATABASE_PORT = 80
local DATABASE_NAME = “”
local DATABASE_USERNAME = “”
local DATABASE_PASSWORD = “”

function printQuery(query)
PrintTable(query:getData())
end

function afterConnected(database)
steamID = ply:GetNWString(“SteamID”)
local query1 = database:query(“SELECT steamid FROM srp WHERE steamid = '”…steamID…"’")
sql.QueryValue( query1 )
query1.onData = function(Q,D) print(“Q1”) PrintTable(D) end
query1.onSuccess = printQuery
query1.onError = function(Q,E) print(“Q1”) print(E) end
query1:start()

if(query1 == false) then  
        Msg("Account doesn't exist

")
ply:PrintMessage( HUD_PRINTTALK, "SRP:Welcome Guest! " … ply:Nick() )
sb_team1( ply )
else
ply:PrintMessage( HUD_PRINTTALK, “SRP:Welcome " … ply:Nick() … " You are a VIP Member!” )
sb_team3( ply )
end
end

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

connectToDatabase()
[/lua]

init.lua
[lua]
function GM:PlayerInitialSpawn( ply )
self.BaseClass:PlayerInitialSpawn( ply )
ply:SetNWString(“SteamID”, SteamID)
local cash = ply:GetPData(“cash”)
//local BackPack = {Code = 1, PropModel = “models/props_junk/watermelon01.mdl”, Name = “Melon”}
//local encodedData = glon.encode(BackPack)
//ile.Write(“items.txt”, encodedData)

    if cash == nil then
        ply:SetPData("cash", STARTMONEY)
        ply:Money_Set(STARTMONEY)
    else
    ply:Money_Set(cash)
    end
    if ply:IsAdmin() then
            sb_team2( ply )
            ply:PrintMessage( HUD_PRINTTALK, "SRP:Welcome Admin! " .. ply:Nick() )
    else // If he isn't admin then,
    afterConnected(database)
    end

end
[/lua]

Why are you including init.lua

Don’t i need to if i want it to select the teams?

sb_team1( ply )/sb_team3( ply )

No, your files are now re-including eachother over and over.

Isn’t this…
[Lua]
local DATABASE_PORT = 80
[/lua]

Supposed to be…
[Lua]
local DATABASE_PORT = 3306
[/lua]

As the default port for mysql is 3306

True, but chances are his IP is blocked anyway (that is if remoteSQL is even supported by the host).

Protip: XAMPP

Alright xampp is installed and running, I am using no-ip to constantly check my ip and update the domain name so that my users may connect to me 24/7. Now then the default for the xampp username is root and the password is nothing am i correct?

No need to run no-ip, just use your local ip unless you are already hosting the server for other people…

im using no-ip cause my ip isn’t static i believe its not at lease. And im going to be buying a domain name anyways from them so i might as well

I am pretty sure your local ip is static. Since you are running the mysql service locally, you could even use 127.0.0.1 or localhost as hostname/ip. Trust me; a direct connection speeds up the connection.