Reputation:
I have a website that is MySQL/PHP. Occasionally, I cannot connect because of
Warning: mysql_connect() [function.mysql-connect]:
User foo has already more than 'max_user_connections' active connections in /home/foo/public_html/utilities.php
I use a discount web host service and can't really prevent it from happening occasionally. (At least I don't think I can.) How can I give the user a friendlier message than this crypic one?
Upvotes: 1
Views: 467
Reputation: 57845
If you turn off displaying errors (which you should probably do in production anyway), then you can then print your own error if the connection attempt fails.
ini_set('display_errors', false);
if (!$link = mysql_connect($host, $user, $pass)) {
die('could not connect...');
}
If you can't change the ini setting, you can suppress the warning with @
if (!$link = @mysql_connect($host, $user, $pass)) {
die('could not connect...');
}
If you suppress the warning, you won't be able to see why the connection failed, which may or may not be what you want. However you could instead log the errors.
Upvotes: 3