Thursday 7 August 2014

How to connect with database in three step in php


Follow the step
Step 1:  Create Database and table.
 
Step2: Enter hostname, Database name.

Step3:Insert Data and Execute the Query.
This is my database and my database name is registration and table name is user.

We are inserting  a data statically(already data is selected).

        
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$database_name='registration';
$password=” ”;
$dbhandle = mysqli_connect('localhost',$username ,$password,$database_name)
or die("Unable to connect to MySQL");
 $name ="Gaurav";
$password1="1234";
 $email="gauravrautela123@gmail.com";
 $query="insert into user set name='".$name."',password='".$password1."', email='".$email."'"; 
$execute =  mysqli_query($dbhandle, $query);
 If($execute)
     {
                 echo "Congrats Data inserted";
 }else{
                echo  "Something Going Wrong";
}
?>
After Insertion :



Terminology:
mysqli_connect(): It is php connection method,we can pass  four argument hostname,username,password,Database name.

Die();It stop the rest of exection if die methiod will exectute and show the

messages.
 

6 comments:

  1. it is really a great tutotrial.. plz keep posting more blogs.

    ReplyDelete
  2. Nice tutotrial you are gaurav rautela,,,good job,,excellent,, keep posting more blogs so that we can get more knowledge.

    ReplyDelete
  3. This Blog is Very Helpful .Great Job Gaurav Rautela Keep it Up...Keep Posting More Blogs ..

    ReplyDelete
  4. This blogs solves my problem ..Very thankful to Gaurav Rautela Keep it up ...keep posting more ...

    ReplyDelete
  5. Great explanation...Buddy..

    ReplyDelete
  6. nice blog bro it is very helpful..............................good job

    ReplyDelete