kicken Posted March 11, 2012 Share Posted March 11, 2012 Kicken, you still missed what I said above... No, your not understanding what I am saying. But back in "article.php" - after the require to "last_activity.php" I have... // Connect to the database. require_once(WEB_ROOT . 'private/mysqli_connect.php'); Yes, you have that. But That file is NOT included The code in that file is NOT run Therefore, you do NOT re-connect You could just delete that line from your script, it would function the exact same way. Quote Link to comment https://forums.phpfreaks.com/topic/258628-successful-update-throws-error/page/2/#findComment-1326075 Share on other sites More sharing options...
scootstah Posted March 11, 2012 Share Posted March 11, 2012 That isn't what I said... I said that at the top of "article.php" I require "last_activity.php"... // Update Last Activity. require_once('../members/last_activity.php'); And that "last_activity.php" opens and closes a database connection like this... // Connect to the database. require_once(WEB_ROOT . 'private/mysqli_connect.php'); // Close prepared statement. mysqli_stmt_close($stmt); // Close the connection. mysqli_close($dbc); But back in "article.php" - after the require - I have... // Connect to the database. require_once(WEB_ROOT . 'private/mysqli_connect.php'); So that should take care of my required file opening and closing the connection, right?! When you require_once something, it does exactly that: requires it once. Any subsequent attempts to include the file fail, because you said you only want to do that once. So you are essentially doing: require_once(WEB_ROOT . 'private/mysqli_connect.php'); ... more code ... require_once(WEB_ROOT . 'private/mysqli_connect.php'); Therefore, the second one won't work. The easiest thing to do here is to just connect to the database earlier than last_activity and don't worry about closing it. Quote Link to comment https://forums.phpfreaks.com/topic/258628-successful-update-throws-error/page/2/#findComment-1326093 Share on other sites More sharing options...
doubledee Posted March 11, 2012 Author Share Posted March 11, 2012 When you require_once something, it does exactly that: requires it once. Any subsequent attempts to include the file fail, because you said you only want to do that once. So you are essentially doing: require_once(WEB_ROOT . 'private/mysqli_connect.php'); ... more code ... require_once(WEB_ROOT . 'private/mysqli_connect.php'); Therefore, the second one won't work. The easiest thing to do here is to just connect to the database earlier than last_activity and don't worry about closing it. My bad! I see where I wasn't getting things. See, that is why you are a guru and I'm just a newb... BTW, if I didn't have require_once and instead had require does it hurt things if I connect to me database more than once? I'm sorta debating where to put my Connection String, because if I just had it "last_activity.php" then some of my parent scripts might fail because they need it too, but if I just put it in the parent scripts but there is a time where I require "last_activity.php" and the aprent script doesn't have a Connection String then "last_activity.php" should have it. I suppose I just need to think things out and have a better strategy?! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/258628-successful-update-throws-error/page/2/#findComment-1326109 Share on other sites More sharing options...
scootstah Posted March 11, 2012 Share Posted March 11, 2012 BTW, if I didn't have require_once and instead had require does it hurt things if I connect to me database more than once? It means you will be connecting to the database more than once, which doesn't make any sense. You are just wasting server resources. I'm sorta debating where to put my Connection String, because if I just had it "last_activity.php" then some of my parent scripts might fail because they need it too, but if I just put it in the parent scripts but there is a time where I require "last_activity.php" and the aprent script doesn't have a Connection String then "last_activity.php" should have it. I suppose I just need to think things out and have a better strategy?! Connect to the database before anything else, and then you don't have to worry about it. Quote Link to comment https://forums.phpfreaks.com/topic/258628-successful-update-throws-error/page/2/#findComment-1326114 Share on other sites More sharing options...
dragon_sa Posted March 11, 2012 Share Posted March 11, 2012 // Close the connection. mysqli_close($dbc) Just remove this from everywhere and let php handle closing the connections and you can leave your require once then Quote Link to comment https://forums.phpfreaks.com/topic/258628-successful-update-throws-error/page/2/#findComment-1326136 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.