Jump to content

How to store the result of a mysql query


Recommended Posts

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 by andreiwow2
Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...