Hi there people of the forum,
var $ConnectionAttempts = 4;
var $conn;
function connect(){
for($i=0; $i<$this->ConnectionAttempts; $i++){
$this->conn = mysql_connect($this->DBhost,$this->DBuser,$this->DBpass);
if($this->conn){
return $this->conn;
break;
}
if($i <> $this->ConnectionAttempts){
$this->PipeError(mysql_error());
header("location: ./path/to/somefiles/ConnectingError.php");
exit;
}
}
}
I think as this works, no, I hope it works, at least it seems to! Basically what I want is for the connect() to try 4 times to establish a connection to the MySql DB, obviously if it connects first time, return the resource #id as a property of the function/method, which I think it does, BUT if it fails for some reason, keep trying until it does. Then if it reaches the limit, I pipe the error message (text file below root of server) and then redirect to a 'Holding page' with a nice friendly message.
The only thing I am thinking of adding is: if(($i <> $this->ConnectionAttempts) || (!$this->conn = NULL)) but I'm not sure, I mean I can't tell if it actually does anything...
That's how I think I have written it to work, but after a long day at work doing VB6/.NET I would like the benefit of a new perspective.
Thanks,
MRb