Jump to content

Recommended Posts

I had someone code my site and they are no longer around. So I'm a php/mySQL newbie. That being said I'm trying to fix a problem I've been having for over a week.

 

It's a real estate website and on the main page it shows "feature properties" that it gets from the database. If i click around and refresh the page a few times. I loss the connection to the database and that page shows nothing.

 

I tried contacting me Web Host and they have increased the max_user connections to 35. That still doesn't solve the problem.

 

Can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/
Share on other sites

The website is loftyfinds.com you will see properties on the front page. When the connect is lost you will get an error message that says: "Currently no Front page Properties"

 

The connect file has the following code:

 

  define('DB_SERVER', 'localhost'); 
  define('DB_SERVER_USERNAME', '********');
  define('DB_SERVER_PASSWORD', '********');
  define('DB_DATABASE', '*********');
  define('USE_PCONNECT', 'false'); 


include 'start.php'; 

It is saying no properties right off the bat.

 

Me personally I like to use a user defined function to make my db connections and have never had a problem with this kind of error.

 

function connectdb()
{
mysql_connect('HOST', 'USERNAME', 'PASSWORD');
mysql_select_db('DATABASE') or die('Unable to select database!');
}

 

Just call this function before you run a query and you should be good to go.

I assume that the db connection is made before every query? I finally got the error, but I am beginning to think that it is an issue with the database provider rather than your script.

 

I may be wrong, but if the connection works once, it should work every time. There really should not be anything in the scripting that could make this happen. As long as your making a DB connection before each query or at least per page that has queries on it, then it should work every time.

 

you might add a mysql_error() in there below one of your queries to see what the error is.

 

Nate

Yeah, I would press the issue. I spent about 5 minutes just clicking links. They worked most of the time so the script is doing what it's supposed to do (but no featured houses are displaying) it is just losing it's connection from time to time.

 

If I were in your shoes, I would be really looking to the provider for an answer. If it works once it should work every time provided there are no changes made to the script. Thats my opinion about scripting. If I confirm that a script does what I want once, then it will work every time. Of course there are a few things that can break a script, but that is generally user input or something along that lines.

 

But as far as I can see, your code is working fine, it just has a little trouble connecting to the database. Try putting an error message to let you know when the database cannot select the db. e.g.

 

mysql_select_db('DATABASE') <--ignore this part.... just this part --> or die('Unable to select database!');

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.