note 45874 deleted from function.mssql-connect by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 22 Sep 2004 19:29:36 +0000 |
| Subject: | note 45874 deleted from function.mssql-connect by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77178@lists.php.net to get a copy of this message | ||
Note Submitter:
----
If you are getting errors with the database not connecting correctly, even after trying only for a
few tenths of a second, try use this code to connect to your database instead. I am still having
this issue. It has been documented at the bug tracker here: http://bugs.php.net/bug.php?id=29074
<?php
function mssql_rconnect($host,$username,$password, $permanant = FALSE, $retryCount = 30)
{
global $temp;
$temp['MsSQLConnCount']++;
if ($permanant === TRUE)
{
$temp['dbConnect'] = @mssql_pconnect ($host,$username,$password);
}
else
{
$temp['dbConnect'] = @mssql_connect ($host,$username,$password);
}
if ($temp['dbConnect'] === FALSE && $temp['MsSQLConnCount'] >=
$retryCount)
{
echo "Could not connect to MsSQL Server. Sorry it didn't work! I tried " .
$temp['MsSQLConnCount'] . " times! <br /><br />MsSQL said this: <br
/>\"" . mssql_get_last_message() . "\"";
exit;
}
else if ($temp['dbConnect'] === FALSE && $temp['MsSQLConnCount'] <
$retryCount)
{
mssql_rconnect();
}
return $temp['MsSQLConnCount'];
}
?>
Connect to MsSQL with the following line
<?php
mssql_rconnect("localhost", "sa", "password", TRUE, 45);
?>
if you have an error reporting script you have, and you want to log when the connect fails,
reference the connect like this:
<?php
if (mssql_rconnect("localhost", "sa", "password", TRUE, 45) != 1)
{
// $temp['MsSQLConnCount'] has the amount of times it took MsSQL_rConnect to connect.
// performYourErrorReportingHere($temp['MsSQLConnCount']);
}
?>
Cheers,
Matt