[mythtv] PATCH: mythweb - add db_open retries

Poul Petersen petersp at MATH.ORST.EDU
Thu Jun 19 22:11:53 EDT 2003


	For some reason, my DB server fails to accept about 1 out of
every 100 access attempts, which generates an error in mythweb
(obviously). This simple patch adds a bit of robustness to db_open.php.

-poul

--- settings.php	2003-05-03 17:51:11.000000000 -0700
+++ /tmp/settings.php	2003-06-19 14:05:04.000000000 -0700
@@ -26,6 +26,7 @@
 	$db_username 	= "mythtv";
 	$db_password 	= "mythtv";
 	$db_dbname	= "mythconverg";
+        $db_connect_retry = "5";
 
 	//
 	//	listing Display options

--- db_open.php	2002-09-10 21:08:52.000000000 -0700
+++ /tmp/db_open.php	2003-06-19 14:02:44.000000000 -0700
@@ -16,7 +16,24 @@
 //
 //	This file (db_open.php) just opens the database connection
 //
+  
+        $i=0;
+
+        while ($i<$db_connect_retry) {
+
+		if ( $linkToDatabase = @mysql_connect($db_host, $db_username, $db_password) ) {
+			break;
+		}
+		else {
+			$i++;
+                }
+        }
+
+        if ($i==$db_connect_retry) {
+
+      		die("Uh oh! I couldn't open a link to the database. Is MySQL running? Did you set the right values in settings.php?");
+
+        }
 
-	$linkToDatabase = mysql_connect($db_host, $db_username, $db_password) or die("Uh oh! I couldn't open a link to the database. Is MySQL running? Did you set the right values in settings.php?");
 	mysql_select_db($db_dbname) or die("Hmmmm, I couldn't open the right database within MySQL. Did you change the database's name? Is MythTV fully installed?");	
 ?>


More information about the mythtv-dev mailing list