Jump to content

[QUESTION]How to export database connection function


DriFtyZ

Recommended Posts

Initialize a connection inside "MySQL" resource, and then make exported functions that once called upon, will use the initialized connection.

For example:

mySQL = dbConnect( "mysql", "dbname=mta;host=localhost", "myserver", "12345")

function query(str)
	if mySQL then
		local query = dbQuery(mySQL, str)
		if not ( query ) then
			return false
		end
		local result, num_rows, id = dbPoll(query, -1)
		return result or false, num_rows or false, id or false
	end
	return false
end

And then in meta.xml simply include:

<export function="query" type="server"/>

 

Edited by Hale
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...