0

When trying to edit table data in one of databases, I can't apply the change because of the error

"MySQL error 2006: mysql server has gone away"`

This problem is intermittent. So I did some research on this and I came across this post. (note: I'm not at all knowledgeable on databases and php). Now I see mysql_ping Pings a server connection or reconnects it if there is no connection.

Sounds great. My issue is how do I apply this mysql_ping? Where do I go and do it? Is it ok to apply it or will it effect certain things?

My server runs off Windows 2003, IIS and I have PHP 5.3.8. I've had a look here but I'm battling to understand it.

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
MSchumacher
  • 167
  • 1
  • 5
  • 13
  • possible duplicate of [MySQL error 2006: mysql server has gone away](http://stackoverflow.com/questions/7942154/mysql-error-2006-mysql-server-has-gone-away) – Ben Nov 13 '13 at 08:24

1 Answers1

0

Make a subroutine/function that includes mysql_ping, and use it insted of mysql_query.

For example

<?php
function my_query($sql)
{
   if(!mysql_ping())
   {
      if(!mysql_connect( /* add connection parameters here */ ))
      {
         trigger_error("Database not avaible: " . mysql_error());
         return FALSE;
      }
   }

   return mysql_query($sql);
}
?>
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Puggan Se
  • 5,738
  • 2
  • 22
  • 48
  • Hi, thanks but I wouldn't know where to add this function? MySQL administrator? – MSchumacher Jun 26 '12 at 22:07
  • i always have all database stuff in one file, that the other files includes, there would be a good place to put it, and then replace all use of mysql_query( whit my_query( – Puggan Se Jun 26 '12 at 22:10
  • Been a layman of PHP, I'd appreciate if you could elaborate? Where are those file that you are talking about? – MSchumacher Jun 26 '12 at 22:19