I sent an email to the mysql list, but it reminded me of a question I had for people structuring their PHP code. What's the general way that people structure their connections? Right now, I spawn off two mysql_connect calls at the top of the file that includes my database calls, using "true" for the fourth parameters, so as to create two new connections. Then I use those two connections for two different databases I have to query from. Is it better just to use mysql_select_db within the query function every time for the same connection? Should I use mysql_connect every time without using "true", so as to re-use connections. Should I be using pconnect instead? I spent some time looking for answers to these questions, but am getting conflicting answers. Some people think relying on the re-use of these functions is good, some think that explicit management is better. In general, how have people on the list found them? For example, is having constant mysql_select_db calls a problem? Thanks, Waynn On Wed, Oct 29, 2008 at 2:47 AM, Waynn Lue <waynnlue@xxxxxxxxx> wrote: > We've started seeing mysql errors in the logs, and when i look at the > output of mysql_error() (in php), i get "lost connection to mysql server > during query". Here's an example stack trace: > > 'Can't connect to <name> database [Lost connection to MySQL server during > query]' > > Similarly, we're seeing stack traces here as well: > > 'Can't connect to <name> database []' > > I usually only see this mesasge when I don't use a connection for awhile > and it timeouts, but in this case, the connection is only opened for the > duration of a script, which can't be running for more than a second. The > mysql error logs don't show anything, and wait_timeout is set to 28800. > > At first, I thought it was because I was calling mysql_select_db too much, > so I ended up using two mysql connections per page load, but that didn't > seem to change anything. How can we prevent this error from happening, what > else can I do to diagnose this further? Google brings up some more > discussions about it, but nothing seems related to this, like packetsize. > This is happening when we select two ids from a database. And SHOW > PROCESSLIST shows that the number of connections aren't even coming close to > max connections. > > Thanks for any advice, > Waynn >