anchor.diff:  	User = gen_mod:get_opt(user, Opts, "root"),
   	Password = gen_mod:get_opt(password, Opts, ""),
   
  -	St = #state{server=Server, port=Port, db=DB,
  -	               user=User, password=Password},
  -
  -	case open_mysql_connection(St) of
  -	    {ok, DBRef} ->
  -	        State = St#state{dbref=DBRef},
  -
  -			ets:new(mod_log_chat_mysql5, [named_table, protected, set, {keypos, 1}]),
  -			ets:insert(mod_log_chat_mysql5, {dbref, DBRef}),
  -
  -	        Result = create_table(State),
  -			?INFO_MSG("create table: ~p", [Result]),
  -	        erlang:monitor(process, DBRef),
  -	        {ok, State};
  -	    {error, Reason} ->
  -	        ?ERROR_MSG("MySQL connection failed: ~p~n", [Reason]),
  -	        {stop, db_connection_failed}
  -	end.
  -
  -open_mysql_connection(#state{server=Server, port=Port, db=DB,
  -                             user=DBUser, password=Password} = _State) ->
  -   LogFun = fun(debug, _Format, _Argument) ->
  -                %?DEBUG(Format, Argument);
  -                 ok;
  -               (error, Format, Argument) ->
  -                 ?ERROR_MSG(Format, Argument);
  -               (Level, Format, Argument) ->
  -                 ?DEBUG("MySQL (~p)~n", [Level]),
  -                 ?DEBUG(Format, Argument)
  -            end,
  -   ?INFO_MSG("Opening mysql connection ~s@~s:~p/~s", [DBUser, Server, Port, DB]),
  -   mysql_conn:start(Server, Port, DBUser, Password, DB, LogFun).
  -
  -cleanup(Host) ->
  -	close_mysql_connection(),
  -    ejabberd_hooks:delete(user_send_packet, Host,
  -			  ?MODULE, log_packet_send, 55),
  -	ok.
  -
  -close_mysql_connection() ->
  -	[{_, DBRef}] = ets:lookup(mod_log_chat_mysql5, dbref),
  -	?DEBUG("Closing ~p mysql connection", [DBRef]),
  -	mysql_conn:stop(DBRef).
  -
  -stop(Host) ->
  -    cleanup(Host),
  -	ok.
  -
  +	?INFO_MSG("Opening mysql connection ~s@~s:~p/~s", [User, Server, Port, DB]),
  +	mysql:start_link(mod_log_chat_mysql5_db, Server, Port, User, Password, DB, LogFun).
  +
  +%%--------------------------------------------------------------------
  +%% Function: terminate(Reason, State) -> void()
  +%% Description: This function is called by a gen_server when it is about to
  +%% terminate. It should be the opposite of Module:init/1 and do any necessary
  +%% cleaning up. When it returns, the gen_server terminates with Reason.
  +%% The return value is ignored.
  +%%--------------------------------------------------------------------
  +terminate(_Reason, _State) ->
  +	mysql:stop(),
  +    ok.
  +
  +%%--------------------------------------------------------------------
  +%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
  +%% Description: Convert process state when code is changed
  +%%--------------------------------------------------------------------
  +code_change(_OldVsn, State, _Extra) ->
  +    {ok, State}.
  +
  +%%--------------------------------------------------------------------
  +%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
  +%%                                      {reply, Reply, State, Timeout} |
  +%%                                      {noreply, State} |
  +%%                                      {noreply, State, Timeout} |
  +%%                                      {stop, Reason, Reply, State} |
  +%%                                      {stop, Reason, State}
  +%% Description: Handling call messages
  +%%--------------------------------------------------------------------
  +handle_call(stop, _From, State) ->
  +    {stop, normal, ok, State}.
  +
  +%%--------------------------------------------------------------------
  +%% Function: handle_cast(Msg, State) -> {noreply, State} |
  +%%                                      {noreply, State, Timeout} |
  +%%                                      {stop, Reason, State}
  +%% Description: Handling cast messages
  +%%--------------------------------------------------------------------
  +handle_cast({insert_row, FromJid, ToJid, Body, Type}, State) ->
  +	?INFO_MSG("inserting row: %p, %p, %s, %s", [FromJid, ToJid, Body, Type]),
  +	Query = ["INSERT INTO ", table_name(), " (fromJid, toJid, sentDate, body, type) VALUES",
  +	 		"(\"",
  +	FromJid,
  +	"\", \"",
  +	ToJid, "\", NOW(), \"",
  +	Body, "\", \"", Type ,"\");"],
  +
  +	sql_query(Query),
  +	{noreply, State}.
  +
  +%% handle module infos
   handle_info({'DOWN', _MonitorRef, process, _Pid, _Info}, State) ->
       {stop, connection_dropped, State};
   handle_info(Info, State) ->
       ?INFO_MSG("Got Info:~p, State:~p", [Info, State]),
       {noreply, State}.
   
  -terminate(_Reason, #state{}=_State) ->
  -	close_mysql_connection(),
  -	ok.
  -
  +%% ejabberd hook
   log_packet_send(From, To, Packet) ->
       log_packet(From, To, Packet).
   
  
positive.code: 
  -define(PROCNAME, ?MODULE).
  
  -record(state, {dbref, server, port, db, user, password}).
  
  table_name() ->
  	"mod_log_chat_mysql5".
  
  start(Host, Opts) ->
  	?INFO_MSG(" ~p  ~p~n", [Host, Opts]),
  	ejabberd_hooks:add(user_send_packet, Host, ?MODULE, log_packet_send, 55),
  	Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
  	gen_server:start({local, Proc}, ?MODULE, [Opts], []).
  
  init([Opts]) ->
      ?INFO_MSG("Starting ~p", [?MODULE]),
  
  	crypto:start(),
  
  	Server = gen_mod:get_opt(server, Opts, "localhost"),
  	Port = gen_mod:get_opt(port, Opts, 3306),
  
negative.code: log_packet(_From, _To, _Packet) ->
      ok.
  
  %% parse message and send to db connection gen_server
  write_packet(From, To, Packet, Type) ->
      Body = escape(html, xml:get_path_s(Packet, [{elem, "body"}, cdata])),
      case Body of
  