[erlang-questions] Newbie Question: Module with DB Connection as a "global state"
Michael Weibel - Amiado Group
Wed Oct 5 15:36:58 CEST 2011
I'm new to erlang, new to this list and I hope here's the right place to ask this question.
I'm currently implementing a module for ejabberd where I need to log certain packets to a MySQL DB and I'm using the MySQL Native Driver for it.
My current implementation is on github:
In this file you see that I'm opening the MySQL Connection in the function "open_mysql_connection" and assign it to a ETS Table because I didn't find another way to store the DB Reference (I tried something with records but didn't succeed).
This worked pretty well but I ran into the problem that after some days/weeks the ets table didn't have the DB Reference anymore.
To prevent this, I want to create functions which setup the DB Connection again, if it doesn't have it anymore.
As I'm trying to do this I run into the problem that the informations about how to connect to the db is only in the init-function available and I don't really want to store this information also in the ets table.
Can anyone help me or point me to a site on how to do this?
More information about the erlang-questions