Jump to content

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


novo

Recommended Posts

Posted

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

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

So, at the start of the .lua*s i must add:

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

¿?

Plz help <3 and thank you

Posted
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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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