Jump to content

MySQL question


_Dark_

Recommended Posts

Yes, it is, export the function and then use it with exports.

I have this code in some file in my resource, called database

MySQL = nil 
function start( ) 
  
    MySQL = mysql_connect("127.0.0.1", "dark", "12345", "DarkLife") 
    if MySQL then 
        outputDebugString("[MySQL] Connection established! ") 
    end 
end 
  
addEventHandler("onResourceStart", getResourceRootElement(), start) 

How to use the MySQL handler in other resources?

Link to comment

This topic should go in the "Scripting", but well.

MySQL = nil 
function start( ) 
    MySQL = mysql_connect("127.0.0.1", "dark", "12345", "DarkLife") 
    if MySQL then 
        outputDebugString("[MySQL] Connection established! ") 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(), start) 
  
function getMySQLHandler() 
    return MySQL 
end 

Then in the meta.xml of THIS resource you must add:

function="getMySQLHandler" type="server" /> 

Then you can use it in other resources like this:

local handler = exports["myHandlerResourceName"]:getMySQLHandler() 

Link to comment
This topic should go in the "Scripting", but well.
MySQL = nil 
function start( ) 
    MySQL = mysql_connect("127.0.0.1", "dark", "12345", "DarkLife") 
    if MySQL then 
        outputDebugString("[MySQL] Connection established! ") 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(), start) 
  
function getMySQLHandler() 
    return MySQL 
end 

Then in the meta.xml of THIS resource you must add:

function="getMySQLHandler" type="server" /> 

Then you can use it in other resources like this:

local handler = exports["myHandlerResourceName"]:getMySQLHandler() 

If you would:) I already did. No.

function start () 
  
    local handler = exports.MySQL:getMySQLHandler() 
    mysql_query(handler, "INSERT INTO `users` SET `login` = 'test', `password` = '1234'") 
end 
addEventHandler("onResourceStart", getResourceRootElement(), start) 

bad argument #1 to `mysql_query` <mysqlHandler expected, got string> 

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