How to connect with MySQL database using PHP



Connecting to MySQL database is very easy. To do this you have to follow some basic steps. Here are the steps: 

  • Create a connection for MySQL database
  • Select the Database
  • Close the Database
Create a connection for MySQL database: To do this you can use mysql_connect() function. This function is used to connect with MySQL database. mysql_connect() function takes three parameter. The first parameter is serverName, second parameter serverUsername and the last parameter is serverPassword. We can write this function like this 
mysql_connect(serverName, serverUsername, ServerPassword)

 
We use Vertigo server. In Vertrigo server the serverName is localhost, the serverUsername is root and the serverPassword is vertrigo so we can write the function like this 
mysql_connect(localhost, root, vertrigo) 
Note: In ZAMMP server there are no password is needed so the server password could be null. 
The real PHP code to connect with MySQL database like this 

<?php
$serverName=”localhost”;
$serverUsername=”root”;
$serverPassword=”vertrigo”;
$create_connection=mysql_connect($serverName, $serverUsername, $serverPassword)
or die(“connection error with mysql database”);
?>

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP