Phil++ 31 Posting Whiz in Training

Hey, what I'm trying to do is create a mysql_connection script that includes a exception handling statement that trys to connect to the database and the table, if one isn't created it goes to a file and the database information is stored there.

<?php
// this file contains the database access information.
// this file also estableishes a connection to mysql and selects the database.
// ths file also defines the escape_data function.

// set the database access information as constants.
try {
DEFINE ('DB_USER', 'username');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'database');

// make the connection
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to mysql: ' . mysql_error() );

// select the database
@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );

}

I dunno where to throw the exceptions, or would you just do an if statement?

if(!mysql_select_db)
{
  // page link
  exit();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.