pouncer Posted April 9, 2009 Share Posted April 9, 2009 I've got this code at the to of my index.php <? require_once("database.php"); require_once("functions.php"); $db = new Database(); $db->Connect(); ?> The Connect() method is just the mysql_connect(...) stuff. So everytime I refresh my index.php, is my web app always executing the mysql_connect?? is there a better way to do it so it just connects once when i open the index.php and not again and again... Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted April 9, 2009 Share Posted April 9, 2009 Use pconnect rather than connect? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 9, 2009 Share Posted April 9, 2009 Yes everytime you refresh the page mysql_connect will be called. However mysql_connect will not establish a new connection if there is an existing one. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 9, 2009 Author Share Posted April 9, 2009 Ah, I never knew about pconnect!! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2009 Share Posted April 9, 2009 pconnect only works for a server module version of PHP. Most hosting runs php as a CGI application and pconnect does not work. Quote Link to comment Share on other sites More sharing options...
revraz Posted April 9, 2009 Share Posted April 9, 2009 I wouldn't worry too much about it, because when the page is finished executing, it closes the connection anyways. Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 9, 2009 Share Posted April 9, 2009 just use, require_once("database_page.php"); Quote Link to comment 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.