Its a general query that How can we connect to MySQL Database within PHP WebPage.First of all you should have the server Host name or IP Address. Then another requirement is Database user name and password to establish a connection with MySQL.
So the initial data that you must need is..
$connection = mysql_connect($hostname, $username, $password);
Here you get refrence of your MySQL connection in $con variable.Now you can check the avalibity of connection by following code..
if (!$connection) {
die('Connection failed: ' . mysql_error());
}
else{
echo "MySQL Database Connection established " ;
}
After establishing a connection with MySQL Server our next step is to select the database through which you want to connect.Perticuler database should be exist at server.
$database=”mydb”;
$db = mysql_select_db($database, $connection);
if (!$db) {
die ('Database connection failed ' . mysql_error());
}
else {
echo 'Database successfully connected!';
}
At last to close the connection we use mysql_close() method
mysql_close($connection);
So now you can go through further database SQL queries to retrieve your desired results.
Software Training & Solution Provider
258,Katewa Nagar,Jaipur,Rajasthan.
It's the near by location of Gurjar ki thadi, MANSAROVAR.
Ph: 9829708506 , 0141-4108506 , 08432830240, 8432706556