I am creating a php restful API and currently I have the database connection information in each function.
//Connect To Database
$hostname=host;
$username=username;
$password=password;
$dbname=dbname;
mysql_connect($hostname, $username, $password) OR DIE('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
mysql_query($sqlApiAccess) or die('Error, insert query failed');
What is the best way of doing this, Can I have one database connection per php file? Or do I need to do it per function that uses the database.