Mysql read data?

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)

I always get nil with it

Thanks in Advance!

Pin isn’t being declared prior to the SQL query. So your quering nil and getting nil

Sorry I don’t get it I coded few things here and there but I never done SQL so I really don’t know what to do and what you mean by that haha…

-- 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

Assuming you are using oxmysql, I believe the recommended syntax is with a question mark

MySQL.Async.fetchAll('SELECT * FROM storage_lockers WHERE pin = ?',{pin},

Also is storage_lockers the name of a column of the table storage_lockers?
If you are just trying to test printing all of the table, do

print(json.encode(result))

Well I am trying to print a row of the table


(The red marked area is what I am trying to get)

and yes I am using oxmysql

But thanks for that code I will try it out as soon I get home x)