Hello everyone I recently tried to programm myself a sql reader to read a column from a table but it doesn’t work and never really tried or done much in SQL and after reading multiple threads I don’t exactly know what to do now (I am trying to get a column called ‘pin’ and not the whole table to be as list)
my current code is:
RegisterCommand('SQL', function(source, args, rawCommand)
MySQL.Async.fetchAll('SELECT * FROM storage_lockers WHERE pin = @pin',{["@pin"] = pin},
function(result) print(result.storage_lockers)
end)
end)
-- You are passing nothing to the pin in the SQL line, I assume you want the first arg passed via the command.
RegisterCommand('SQL', function(source, args, rawCommand)
local pin = args[1]
MySQL.Async.fetchAll('SELECT * FROM storage_lockers WHERE pin = @pin',{["@pin"] = pin},
function(result) print(result.storage_lockers)
end)
end)
You would use /SQL 1234
1234 being the first args passed after the command.
The local pin is needed as your line of MySQL.Async has {[“@pin”] = pin}, however you never declared it, so it was a nil value.
Really your command was doing nothing because it had nothing passed too it.
And because your trying to make a command you need to get the args passed to the command.
Also, the return on a fetchAll will probably be a table, you may want to print(result[1].storage_lockers)
The end of that script is not a command I just use a command now to try if the script is functioning the end I plan on doing is a circle where you have to enter one pin of the database to be able to enter