Jump to content

Set Connect to a mysql database for all the .luas ? Help !


novo

Recommended Posts

Hi all.

I wanna set:

  
handler = mysql_connect("127.0.0.1", "****", "******", "n30x") 
  

It's for example if i later do:

sql = executeSQLSelect 

it doesn't know to wich database connect.

I wanna know how to make mysql_connect for all the code. I don't want to add mysql_connect to all functions.

Please help :S

Link to comment

Do this, create a main resource, example: "mysql", after that connect to MySQL on resource start and make a function like this:

function getMySQLConnection() 
     return handler 
end 

And in the meta.xml of this resource add this:

function="getMySQLConnection" type="server" /> 

Then you can just use the handler like this:

local handler = exports["mysql"]:getMySQLConnection() 

Link to comment
addEventHandler("onResourceStart",resourceRoot, 
function () 
     handler = mysql_connect("127.0.0.1", "****", "******", "n30x") 
     if (handler) then 
          outputDebugString("Successfully connected to the MySQL server.") 
     else 
          outputDebugString("Unable to connect to the MySQL server.",1) 
     end 
end) 
  
function getMySQLConnection() 
     return handler 
end 

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