So basically I want to send data to the Garry's Mod SQLite file (server.db) when I press a Derma button. I've never used Lua with MySQL. Could someone please help me? Here's a video to clarify what I'm asking:
[video]https://youtu.be/_hioXQO30i8[/video]
Thanks a lot, guys!
P.S. - I know I'd have to go into:
[code]
function DButton:DoClick()
-- Add shit here
DButton:Close()
end
[/code]
However I'm not sure if I'd use the net library, precache things, ect.
Please help!
You would need to use the net library to tell the server to run a query.
Here's a good example of a query [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/sql/Query]sql.Query[/url]
[QUOTE=Nick78111;50388741]You would need to use the net library to tell the server to run a query.
Here's a good example of a query [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/sql/Query]sql.Query[/url][/QUOTE]
Considering the second function in the example has an invalid format, it's not that good.
You'd have to create the table first in the server-side by checking if it exists (sql.TableExists()), and creating it (sql.Query()).
I don't have much time to write some code, but I'll do it later on.
[QUOTE=Tupac;50388838]You'd have to create the table first in the server-side by checking if it exists (sql.TableExists()), and creating it (sql.Query()).
[/QUOTE]
You don't need to use [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/sql/TableExists"]sql.TableExists[/URL] at all, simply do
[code]
sql.Query "CREATE TABLE IF NOT EXISTS 'sometable' (tabledata)"
[/code]
Only use [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/sql/TableExists"]sql.TableExists[/URL] if you need to actually run something other than sql if it doesn't exist
w3schools has [URL="http://www.w3schools.com/sql/default.asp"]this[/URL] great tutorial on SQL. I suggest you follow that tutorial (or at least some of it). Then getting your head around the SQL functions of GMod becomes a bit easier.
Oh, and when testing data return results, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/PrintTable]PrintTable[/url] is your best friend.
Sorry, you need to Log In to post a reply to this thread.