arianhojat Posted June 21, 2006 Share Posted June 21, 2006 whenever i perform a query, i got into the habit of supplying the database and table by calling mysql_connect() everytime, just in case the table changes which it might or to be explicit when checking my code.is this a performance hit, should it not be done unless table definately changes?Example:[code]$host = "localhost"; $user = "user"; $pass = "pass"; $db = "clientsInfo"; $query = "SELECT * FROM clientsInfo.clients";$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); //...later$host = "localhost"; $user = "user"; $pass = "pass"; $db = "clientsInfo"; $query = "SELECT * FROM clientsInfo.clientAddresses";$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); [/code] Link to comment https://forums.phpfreaks.com/topic/12537-when-to-maek-a-new-connection-to-database/ Share on other sites More sharing options...
poirot Posted June 21, 2006 Share Posted June 21, 2006 You call mysql_connect ONCE, unless you want to make different [b]connections[/b].You call mysql_select_db ONCE, unless you want to use different [b]databases[/b].If you are using the same connection, and the same database, it is definitely a waste of resources. Link to comment https://forums.phpfreaks.com/topic/12537-when-to-maek-a-new-connection-to-database/#findComment-48019 Share on other sites More sharing options...
arianhojat Posted June 21, 2006 Author Share Posted June 21, 2006 wow thanx, makes alot of sense. doh. Link to comment https://forums.phpfreaks.com/topic/12537-when-to-maek-a-new-connection-to-database/#findComment-48031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.