andreiwow2 Posted May 27, 2017 Share Posted May 27, 2017 (edited) Hey guys, I've checked the wiki but I don't really understand it, my question is, how do I print or store the result of a query? For example. dbQuery( myCallback, handler, "SELECT * FROM USERS LIMIT 1" ) How do I store the values in a table for exame? userInfo = {}; Also, when should I use ; and when not? Because I see so many examples, some use ; and others doesn't... I've tried this: function createPayPhone() handler = dbConnect( "mysql", "dbname=somedb;host=x.x.x", "someuser", "somepass", "share=1" ) if ( not handler ) then outputDebugString("Unable to connect to the MySQL server") else outputChatBox("Connected") local check = dbQuery(, handler, "SELECT * FROM USERS LIMIT 1" ) local result = dbPoll (check, 2000) for _, row in ipairs ( result ) do for column, value in pairs ( row ) do end outputChatBox(row["USERNAME"]) end end end addCommandHandler("testcon", createPayPhone) but nothing happens when I type the command. #FIXED, the issue was a misplaced " , "! Edited May 27, 2017 by andreiwow2 Link to comment
pa3ck Posted May 27, 2017 Share Posted May 27, 2017 When using dbQuery, you will also need to use the function dbPoll which will automatically put the result in a table. You don't really need to use the ';' when doing single queries, but you will need it when executing multiple SQL queries with a single dbQuery or dbExec. Link to comment
andreiwow2 Posted May 27, 2017 Author Share Posted May 27, 2017 7 minutes ago, pa3ck said: When using dbQuery, you will also need to use the function dbPoll which will automatically put the result in a table. You don't really need to use the ';' when doing single queries, but you will need it when executing multiple SQL queries with a single dbQuery or dbExec. And how do I get the result from dbPoll? Like if I want to print the USERNAME Link to comment
pa3ck Posted May 27, 2017 Share Posted May 27, 2017 row["USERNAME"] should work, I see you edited your question, is your problem resolved now? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now