[erlang-questions] Newbie Question: Module with DB Connection as a "global state"

Gustav Simonsson gustav@REDACTED
Wed Oct 5 15:54:59 CEST 2011


Hi Michael!

On line 48 in your code you store the connection information used in
open_mysql_connection/1 in the state of the server. Perhaps you can
make use of that?

Regards,
Gustav Simonsson

On Wed, 2011-10-05 at 15:36 +0200, Michael Weibel - Amiado Group wrote:
> Hi all,
> 
> 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:
> https://github.com/amiadogroup/mod_log_chat_mysql5/blob/master/src/mod_log_chat_mysql5.erl
> 
> 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?
> 
> Thanks,
> Michael
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list