On Fri, 2005-11-04 at 13:34 +0000, Daniel McBrearty wrote: > It seems the problem is caused by the connection timing out, after which it > automatically reconnects - but set names is not then done. (I am not using > Apache::DBI.) > > Possible solutions: > - modify code to issue set names at the start of every request (a small but > acceptable overhead). > - turn off the auto-reconnect somehow. > > But I can't help feeling I'm redesigning the wheel here - would I have the > same > problem if I used Apache::DBI? Are there other easier ways to handle this?
Turning off the auto-reconnect should be a simple change in your MySQL conf file. Apache::DBI doesn't provide a hook for doing something whenever it makes a new connection, but it would be easy to just add your SET NAMES into the code at that point. Apache::DBI is a very simple module and easy to change. If you don't want to touch Apache::DBI, setting it at the beginning of every request is your best option. You could do that in something like a Fixup handler or do it the first time the handle is requested if you don't always need it. Your other option is writing your own database connection handler, as you seem to have done before. I don't really recommend that, since there are many possible mistakes. The code you showed in your last post would not be able to recover a connection that times out. - Perrin