_Dark_ Posted November 19, 2011 Posted November 19, 2011 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?
Castillo Posted November 19, 2011 Posted November 19, 2011 Yes, it is, export the function and then use it with exports. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
_Dark_ Posted November 19, 2011 Author Posted November 19, 2011 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?
Castillo Posted November 19, 2011 Posted November 19, 2011 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. Education is the most powerful weapon which you can use to change the world.
_Dark_ Posted November 19, 2011 Author Posted November 19, 2011 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?
Castillo Posted November 19, 2011 Posted November 19, 2011 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. Education is the most powerful weapon which you can use to change the world.
_Dark_ Posted November 19, 2011 Author Posted November 19, 2011 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?
AeroXbird Posted November 19, 2011 Posted November 19, 2011 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? The SQL resource from mta-paradise is perfect for your needs. here's a link: https://github.com/mabako/mta-paradise
_Dark_ Posted November 19, 2011 Author Posted November 19, 2011 I saw this resource. Thank you. #define if while#define TRUE FALSE// problems?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now