Step 2: Creating a db_connect.inc.php file
This file will be used to manage the connection to the database.
File db_connect.inc.php:
This file will be used to manage the connection to the database.
File db_connect.inc.php:
<?php
// Database settings // database hostname or IP. default:localhost // localhost will be correct for 99% of times $db_host="localhost";// Database user nmae $db_user="root";// Database password $db_pass=""; // Database name $db_dbname="loginsystem"; /* ############## Make the mysql connection ###########*/ $conn = mysql_connect($db_host,$db_user , $db_pass) or die('Could not connect !<br />Please contact the site\'s administrator.'.mysql_error()); /***************** select the database***************/ $db = mysql_select_db("$db_dbname",$conn) or die('Could not connect to database !<br />Please contact the site\'s administrator.'.mysql_error());
?>
Lets Look at the Quick Explanation of the Above Program
- $db_host="localhost"; // This is the Host name and it is compulsory to write in in order to connect to our Host moreover this is the location for the database server it can be a hostname or an ip adress. it is usualy localhost.
- $d_user="root"; // The is Username of host in mine case I have written "root" because I am connecting to my local server but if you have the Host user name then you should enter the Host user name given by our hosting Provider. In short, this is the database user account used to access the database.
- $db_pass=""; // This is the password for the database user account. I have left it blank because I have not given password to my local server.
- $db_dbname="loginsystem"; // Here we are Entering Our Database name "loginsystem".
- Mysql_connect() fuction is used to connect to server by taking details which we have entered in it like:- hostname, username and password.
- Mysql_select_db() -this function is used to select the database on which you want to work
Note: if You Still in Doubt then or unable to connect to Database or any Errors then Let me know . I May Help you.
No comments:
Post a Comment