_Dark_ Posted November 19, 2011 Share 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 Link to comment
Castillo Posted November 19, 2011 Share Posted November 19, 2011 Yes, it is, export the function and then use it with exports. Link to comment
_Dark_ Posted November 19, 2011 Author Share 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? Link to comment
Castillo Posted November 19, 2011 Share 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() Link to comment
_Dark_ Posted November 19, 2011 Author Share 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> Link to comment
Castillo Posted November 19, 2011 Share 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. Link to comment
_Dark_ Posted November 19, 2011 Author Share 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? Link to comment
AeroXbird Posted November 19, 2011 Share 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 Link to comment
_Dark_ Posted November 19, 2011 Author Share Posted November 19, 2011 I saw this resource. Thank you. Link to comment
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