Connect to a Database

This is the file db_connect.php to be included in a file that needs a connection to the database.

<?php

	// set the database access info as constants
	DEFINE ('DB_HOST', "localhost");
	DEFINE ('DB_USER', "username");
	DEFINE ('DB_PASSWORD', "password");
	DEFINE ('DB_NAME', "databasename");
	DEFINE ('TABLE_NAME', "users");

	//Opening the connection to the database server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if (!link) {
    	die('Not connected : ' . mysql_error());
	}
	// select a database
	$db_selected = mysql_select_db(DB_NAME, $link);
	if (!$db_selected) {
    	die ('Can\'t use the database : ' . mysql_error());
	}

?>

Registration Example | Start | Header | Footer | Connect to a Database | Create a Table | Register | Activation | Login | Logout | Forgot Password | Change Password
© 2008: Hann So
email: hso@voyager.deanza.edu