Forum Moderators: coopster

Message Too Old, No Replies

php errors / max_connections error with mysql

         

jake66

7:34 am on Jul 5, 2006 (gmt 0)

10+ Year Member



i realize this is just a part of using databases, but is it possible to insert a more visitor-friendly page in place of the crappy max_sql_connections and giving them the full patch to sensitive files?

something like
if ($mysql_max_connections) {
redirect('friendly_error.php');
}

i'm no php whiz but surely someone out there has achieved such a thing?

jatar_k

6:41 pm on Jul 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can't remember, if you connect and you don't get a connection back can you handle it there? or does it just throw the error no matter what?

coopster

3:24 pm on Jul 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually it sounds as if you have error_reporting set on your LIVE site. That, in and of itself, is not a good security practice. Turn up error reporting on your TEST server, but use the logs to record messages in your LIVE environment.

jake66

8:22 pm on Jul 11, 2006 (gmt 0)

10+ Year Member



Actually it sounds as if you have error_reporting set on your LIVE site.

i'm on a shared server, so i'm not sure if i have control over this?

regardless of my permissions, surely there's a way to redirect the user to a designated "we'll be back shortly" page that can use my own stylesheets and such - just like a 404 page... or am i mistaken?

right now, the error is:
Warning: mysql_connect(): User database_user_name has already more than 'max_user_connections' active connections in /home/mysite/public_html/directory/database_file.php on line 20
Unable to connect to database server!

barns101

10:33 pm on Jul 11, 2006 (gmt 0)

10+ Year Member



You may be able to suppress the error message by adding the "@" character before your connect string:


@mysql_connect("localhost","user","pass");

jatar_k

11:17 pm on Jul 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you use the @ symbol and then handle the actual error by testing the connection then you should be able to send them off to a nice error page

StupidScript

11:25 pm on Jul 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since this is a db connection issue, could you test for connection success, and redirect on error?

$dbconn=mysql_connect('host','user','passw');

if (!$dbconn) {

header("Location: db_server_too_busy_now.html");

exit;

}

<edit>Oops! Beat me again, jatar_k!</edit>

[edited by: StupidScript at 11:32 pm (utc) on July 11, 2006]

barns101

7:07 am on Jul 12, 2006 (gmt 0)

10+ Year Member




$dbconn=mysql_connect('host','user','passw');
if (!$dbconn) {
header("Location: db_server_too_busy_now.html");
exit;
}

This would still display the error, which would then prevent the header being sent, as output will have been generated. But adding the "@" symbol should do the trick:


$dbconn=@mysql_connect('host','user','passw');
if (!$dbconn) {
header("Location: db_server_too_busy_now.html");
exit;
}

jake66

5:49 am on Jul 13, 2006 (gmt 0)

10+ Year Member



thanks!

what about use in oscomm sites? the database calls seem a bit different.

from includes/database.php
query (is this the correct one?):

function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
global $$link;

or application_top.php

// make a connection to the database... now
tep_db_connect() or die('Unable to connect to database server!');

barns101

2:15 pm on Jul 13, 2006 (gmt 0)

10+ Year Member



That's a custom function but I guess you could suppress errors by putting the "@" right in front of the function:


@tep_db_connect() or die('Unable to connect to database server!');

jake66

5:00 pm on Jul 14, 2006 (gmt 0)

10+ Year Member



That's a custom function but I guess you could suppress errors by putting the "@" right in front of the function:

@tep_db_connect() or die('Unable to connect to database server!');

is it still possible to incorporate

$dbconn=@mysql_connect('host','user','passw');
if (!$dbconn) {
header("Location: db_server_too_busy_now.html");
exit;
}

what would i put in place of $dbconn?

jatar_k

5:25 pm on Jul 14, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



there should be a var somewhere containing the connection, you just need to figure out what it is and then test that.

you could look at the function tep_db_connect and put it right into it.

jake66

6:34 pm on Jul 15, 2006 (gmt 0)

10+ Year Member



thank you, that works perfectly :)