Thanks to those who responded to me privately. 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? cheers Daniel