SQL ConnectToDatabase Function
Saturday, August 23rd, 2008
Carrying on from my last post about connecting to an SQL database using PHP, here are the functions I use to open and close database connections (Note: » just extends the line, you’ll need to remove that for this to work correctly).
// to open the database function connectToDatabase () { $link = mysql_connect("localhost", "database_name", » "database_password"); if ($link && mysql_select_db("database_name")); return ($link); return (FALSE); }// to close the database function db_close($connecter) { mysql_close($connecter); }
It’s a good idea to keep these database connection functions in one place and then reuse them as you need, rather than repeating them everywhere.






