HomeStar Posted August 26, 2007 Share Posted August 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/ Share on other sites More sharing options...
matthewhaworth Posted August 26, 2007 Share Posted August 26, 2007 Show the PHP? Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334295 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 Can you give a link so we can take a look at it ourselves? Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334300 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 Try to use a persistant connection with mysql_pconnect() instead of mysql_connect(). It will try to keep the connection alive even after the script ends. Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334302 Share on other sites More sharing options...
HomeStar Posted August 26, 2007 Author Share Posted August 26, 2007 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'; Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334329 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334335 Share on other sites More sharing options...
HomeStar Posted August 26, 2007 Author Share Posted August 26, 2007 It works for a while. Then fails after surfing around the site. Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334349 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334359 Share on other sites More sharing options...
HomeStar Posted August 26, 2007 Author Share Posted August 26, 2007 It was working for the longest time with no problems. Then it just started doing it ... and you know how service providers are ... it's never their fault. I will back to them and ask again. Thanks for the feedback. Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334362 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 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!'); Quote Link to comment https://forums.phpfreaks.com/topic/66722-connection-fails-after-i-refresh/#findComment-334365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.