How to Connect to Mysql Database


To access the database tables from mysql you need to make connection with database. To complete this task you can use mysql_connect() function.

To do this in php language through. Choose your favorite Editor (Note Pad, Dreamweaver etc) then create a php file called connect.php. Now Inside connect.php file you apply below written codes.

Example :

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Not Successful Connected to Database ' . mysql_error());
  }

// Here is your codes Like Display Information from Database or Edit information etc.

?>

Now you saw the codes where $con is a connection variable which hold the all connection information. In mysql_connection() a localhost is server name that show above script run on local server and next two places are username and password where root is default username of mysql and password is by default null. If condition check the if variable $con hold not hold right information about connection then display message “Not Successful Connected to Database”. Next part is where you write your own script codes for data manipulation.
Share:

No comments:

Post a Comment