MySQL Database Php

function opendatabase ($host,$user,$pass) { 
try { 
if ($db = mysql_connect ($host,$user,$pass)){ 
return $db; 
} else { 
throw new exception ("Sorry, could not connect to mysql."); 
} 
} catch (exception $e) { 
echo $e->getmessage (); 
} 
} 
function selectdb ($whichdb, $db){ 
try { 
if (!mysql_select_db ($whichdb,$db)){ 
throw new exception ("Sorry, database could not be opened."); 
} 
} catch (exception $e) { 
echo $e->getmessage(); 
} 
} 
function closedatabase ($db){ 
mysql_close ($db); 
} 
$db = opendatabase ("localhost","root",""); 
selectdb ("mydatabase",$db); 
$updatequery = "DELETE FROM mytable WHERE id=2"; 
try { 
if (mysql_query ($updatequery, $db)){ 
echo "Your record has been removed."; 
if ($aquery = mysql_query ("SELECT * FROM mytable WHERE id=2")){ 
echo "" . mysql_num_rows ($aquery);
} else { 
echo mysql_error(); 
} 
} else { 
throw new exception (mysql_error()); 
} 
} catch (exception $e) { 
echo $e->getmessage(); 
} 
closedatabase ($db); 
?>