Help with mysqloo

Hi, i using mysqloo at my server and I need to make it:



local db = mysqloo.connect( "127.0.0.1", "root", "", "dbname", 3306 )

function db:onConnected()
	local q = self:query( "SELECT 5+5" )
	function q:onSuccess( data )
		PrintTable( data )
	end
	...
	q:start()
end
...
db:connect()


a little bit easy to write, like this:



sql.mysqloo = function(onconnect)
	local db = mysqloo.connect( host, user, password, dbname, port )
	onconnect(db)
	...
	db:connect()
end


and use it:



sql.mysqloo(function(conn)
	local q = conn:query( "SELECT 5+5" ) -- Problem is here. Conn = [Database], q = nil //Why??
	function q:onSuccess( data )
		print("Yeeey")
	end
	q:start()
end)


Please if u wanna tell me that it isn’t really shorter then first version don’t do it. It’s just for example.

P.S. Sorry for my English.

[editline]9th October 2015[/editline]

I solved it.
Just wrong syntax.



sql.mysqloo = function(onconnect)
	local db = mysqloo.connect( host, user, password, dbname, port )
	db:onConnected()
		onconnect(self)
	end
	...
	db:connect()
end