note 45874 added to function.mssql-connect

From: Date: Wed, 22 Sep 2004 06:44:02 +0000
Subject: note 45874 added to function.mssql-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-77142@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.mssql-connect.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45874 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45874&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45874&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77142) next »