PHP mySQL close connection
So I have been creating lots of new features for me to maintain my cocktail making website. One feature has involved me setting up a new mySQL 5.0 database (with cool stored procedures I am only starting to understand now) in order to do some tracking of what is happening on the site and with my widget. This has required me to use two databases at once for the first time. One to check if a user is signed in with admin rights and the other to check the tracking out of the other database (php security is really tricky so I am slightly nervous posting even this here :s ).
However I did want to note how you close a connection with a mysql database using PHP in order to open one with another mysql database since it's really simple but I found it hard to get info. Here is an example (with $hostname, $username, $password and $databasename containing what they are named):
<?php$link = mysql_pconnect("$hosturl", "$username", "$password")or die("Could not connect: " . mysql_error());
$db = mysql_select_db($databasename,$link)
or die ("Couldn't select database");
?>
mysql_close($link);
So when you open databases try closing them, I know I will in future for good practice, it makes everything much simpler if you add another database at a later stage.

Comments