best to just do a test like:
if (mysql_select_db($db)) {
// do regular stuff
} else {
// create database since it doesn't exist
mysql_query("create database stuff");
}
mysql_select_db returns false if it can't select the requested database. As long as your mysql_connect or mysql_pconnect don't throw an error, this should work just fine.