[CODE][ERROR] addons/custommysql/lua/autorun/sv_mysql.lua:12: attempt to index upvalue
'DB' (a boolean value)
1. fn - addons/custommysql/lua/autorun/sv_mysql.lua:12
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179
[/CODE]
I get this error everytime I try to use the code.
This is on line 12: DB:Query("CREATE DATABASE IF NOT EXISTS " ..Database_name)
[CODE]
Database_name = "testmysql"[/CODE]
As the error suggests, the "DB" variable is a boolean and the code tries to use it as an object.
[editline]11th May 2016[/editline]
It is possible that some poorly coded addon you have installed overrides the global variable "DB" and/or the "custommysql" addon is doing something wrong.
[CODE]local DB, error = tmysql.initialize( HOST, USRNAME, PWD, Database_name, PORT, nil, CLIENT_MULTI_STATEMENTS )[/CODE]
That's where it initialises the code so I doubt it that it'd be conflicting with something else.
EDIT: unless globals also affect locals then I'll be screwed :P
Did your database connect successfully?
Yeah, I am assuming then that the tmysql.initialize function failed and DB becomes "false" and the addon does not check for that.
It is indeed connected.
EDIT: Or it doesn't show any errors concerning that.
Is there any way for me to check if it's connected or not?
This is what I tried:
[CODE]local HOST = "127.0.0.1"
local USRNAME = "username"
local PWD = "****"
local Database_name = "testmysql"
local PORT = 3306[/CODE]
[CODE]lua_run DB, error = tmysql.Connect( HOST, USRNAME, PWD, Database_name, PORT, nil, CLIENT_MULTI_STATEM
> DB, error = tmysql.Connect( HOST, USRNAME, PWD, Database_name, PORT, nil, CLIENT_MULTI_STATEMENTS )...
[ERROR] lua_run:1: bad argument #1 to 'Connect' (string expected, got nil)
1. Connect - [C]:-1
2. unknown - lua_run:1
[/CODE]
You can't access local variables declared in some file from lua_run.
[editline]11th May 2016[/editline]
Also you probably don't want to share your passwords like that.
[QUOTE=Robotboy655;50300300]You can't access local variables declared in some file from lua_run.
[editline]11th May 2016[/editline]
Also you probably don't want to share your passwords like that.[/QUOTE]
Shit, just did that without realising
You know what, here's the whole code. I'm confused af.
[CODE]
HOST = "127.0.0.1"
USRNAME = "username"
PWD = "****"
Database_name = "testmysql"
PORT = 3306
local DB, error = tmysql.initialize( HOST, USRNAME, PWD, Database_name, PORT, nil, CLIENT_MULTI_STATEMENTS )
function SHAD_FirstTime()
DB:Query("CREATE DATABASE IF NOT EXISTS " ..Database_name)
DB:Query("CREATE TABLE IF NOT EXISTS test (steam_id VARCHAR(255), player_name VARCHAR(255), joined_at DATETIME, play_count MEDIUMINT)")
end
hook.Add("Initialize", "Creating tables at start", SHAD_FirstTime )
function SHAD_PlayerJoined(networkid, name)
--local steamid = networkid[0]
--local playername = name
local Timestamp = os.time()
local firstjointime = os.date( "%d/%m/%Y %H:%M:%S", Timestamp )
local result = DB:Query("SELECT steam_id FROM testmysql WHERE steam_id = "..steamid)
if result then
print("[MYSQL]" ..playername.. " already exists in database!")
else
DB:Query("INSERT INTO test (steam_id, player_name, joined_at) VALUES ("..steamid..", "..playername..", "..firstjointime..") ")
DB:Query("UPDATE test SET play_count = play_count + 1 WHERE steam_id = "..steamid)
end
end
gameevent.Listen("player_connect")
hook.Add("player_connect", "dalfskj", SHAD_PlayerJoined)
[/CODE]
Print what DB and error is after you Initialize.
alright so apparently my database wasn't there, woops.
But now that it's actually connecting I get this error whenever someone joins:
[CODE][[GG] Shadow2hel|2|STEAM_0:1:55217946] Lua Error:
[ERROR] addons/custommysql/lua/autorun/sv_mysql.lua:8: attempt to index global 'tmysql' (a nil value)
1. unknown - addons/custommysql/lua/autorun/sv_mysql.lua:8
[/CODE]
You're running the file shared.
[QUOTE=code_gs;50301601]You're running the file shared.[/QUOTE]
As I've said in the other thread, this is how it looks in my shared.lua:
[CODE]if SERVER then
include("sv_mysql.lua")
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.