Possible low db user connection limit solution.

I have a web host that set the user database connection limit way low causing ‘unable to connect to database’ errors. This is what I used to hopefully overcome this problem, thought I would share this with the community see if this helps someone else or one of the more experienced members could improve on it (or have a better solution).

Note: this was not tested extensively (use at your own risk).

In the wp-config.php file replace lines:

/** MySQL database username */

define(‘DB_USER’, ‘wpdbusername’:wink:;

/** MySQL database password */

define(‘DB_PASSWORD’, ‘wpdbpassword’:wink:;

with the code below:

/* MySQL database connection limit fail-over *

* By Wayne D Schulz (CC BY-SA) 2013/04/19 */

$aUser = array( ‘user1’, ‘user2’, ‘user3’, ‘user4’, ‘user5’, ‘user6’, ‘user7’, ‘user8’, ‘user9’ );

$aPass = array( ‘pass1’, ‘pass2’, ‘pass3’, ‘pass4’, ‘pass5’, ‘pass6’, ‘pass7’, ‘pass8’, ‘pass9’ );

for($i=0; $i<sizeof($aUser); $i++) {

$dbLink = mysql_connect(“localhost”,$aUser[$i],$aPass[$i]);

if (!$dbLink) {

$errorlist .= date(“D M j G:i:s T Y”, time()).” – “.mysql_error().”rn”;

error_log($errorlist, 3, “/var/tmp/connect-errors.log”:wink:;

}else{

$dbUser = $aUser[$i];

$dbPass = $aPass[$i];

mysql_close($dbLink);

break;

}

}

/* last dbUser and dbPass */

if (!isset($dbUser)) { $dbUser = “user10”; }

if (!isset($dbPass)) { $dbPass = “pass10”; }

/** MySQL database username */

define(‘DB_USER’, $dbUser);

/** MySQL database password */

define(‘DB_PASSWORD’, $dbPass);