Jump to content

MySQL question


_Dark_

Recommended Posts

Posted

I need to use different resources at connection to MySQL.

Is it possible to create a one connection at one resource and in others use it? If yes, how?

I'm using a MySQL-Module, not standard dbConnect

 #define if while#define TRUE FALSE// problems?
Posted

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

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

 #define if while#define TRUE FALSE// problems?
Posted

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

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

 #define if while#define TRUE FALSE// problems?
Posted

I don't know, for me works perfectly, but I'm using the new MTA DB functions, so maybe is different.

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
I don't know, for me works perfectly, but I'm using the new MTA DB functions, so maybe is different.

yes, but i'm using the module...

Is there any ideas?

 #define if while#define TRUE FALSE// problems?

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