Hi, I am relatively new to php myself but i think I am correct in saying that that info should always be in it's own file as if you have server problems or php handling problems it would display all this info in screen.
<?php
$db_host="localhost";
$db_user="username";
$db_password="password";
$db_name="db name";
?>
Save these 4 lines of code as a file as anything you like. eg : db_con.php
Then to link to this file use this (or similar) on your page:
require ($_SERVER["DOCUMENT_ROOT"] ."/db_con.php") ;
$connection = mysql_connect ($db_host, $db_user, $db_password) or die ("error connecting") ;
mysql_select_db ($db_name, $connection);
My connection file is in a passworded folder in my root directory on the server for added security