tjmbc Posted April 30, 2008 Share Posted April 30, 2008 Can I use this function: function mysqldb(){ $host = "host"; $user = "user"; $password = "password"; $database = "database"; mysql_connect($host,$user,$password) or die ("Unable to connect to the server."); mysql_select_db($database) or die ("Unable to connect to the database."); } to connect to my database by including it in each page and then calling it with: mysqldb(); I know that this is something I should just try out and see what happens, but I can't at this time. Long story... Link to comment https://forums.phpfreaks.com/topic/103579-using-a-function-to-connect-to-mysql/ Share on other sites More sharing options...
Rohan Shenoy Posted April 30, 2008 Share Posted April 30, 2008 Ya, include it in each script and call the function. Link to comment https://forums.phpfreaks.com/topic/103579-using-a-function-to-connect-to-mysql/#findComment-530418 Share on other sites More sharing options...
miracle_potential Posted April 30, 2008 Share Posted April 30, 2008 Yeah that should work good, although why dont you just connect as usual and use include("filename.php"); ?? be easier surely Link to comment https://forums.phpfreaks.com/topic/103579-using-a-function-to-connect-to-mysql/#findComment-530420 Share on other sites More sharing options...
947740 Posted April 30, 2008 Share Posted April 30, 2008 If you have to do the connection over every single page of a website, it will save space having a function. It may not be very much space, but it is space nonetheless. Link to comment https://forums.phpfreaks.com/topic/103579-using-a-function-to-connect-to-mysql/#findComment-530430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.