alecks Posted October 27, 2007 Share Posted October 27, 2007 I was wondering: If I've only got one database that I need to use, would it be better to simply mysql_connect at the beginning of the script and stay connected until the end, or connect each time I need to query? I was doing it the latter way, here is the function that I was using... function basic_query($query){ mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $result = mysql_query($query) or die(mysql_error()); mysql_close(); return $result; } The returned $result could then be used in a fetch array loop, etc... Is there a better way to do this? Link to comment https://forums.phpfreaks.com/topic/75005-solved-mysql-questions/ Share on other sites More sharing options...
kellz Posted October 27, 2007 Share Posted October 27, 2007 i would stay connected.. that's less code and less code is good if it works!^^ Link to comment https://forums.phpfreaks.com/topic/75005-solved-mysql-questions/#findComment-379286 Share on other sites More sharing options...
unidox Posted October 27, 2007 Share Posted October 27, 2007 Less is always better. Make a sql.inc.php page and include it on all the pages that use a query. More organized. Link to comment https://forums.phpfreaks.com/topic/75005-solved-mysql-questions/#findComment-379292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.