database connectivity in php

 First Create a database using phpmyadmin

1 create database using database table



only type database name and then click create



2 then type the table name 
eg. users
3 then select the value of which you want and then click go button
eg. crname, name, age, salary

4 then select the insert button on the top of the section and insert values on the created values 

database connection using php

data.php

<?php

$servername = "localhost";
$username = "root";
$password = "";
$database = "phpsample";

// creating database connection 
$conn = mysqli_connect($servername,$username,$password,$database);

// check connection
if(!$conn){
    die("Failed to connect". mysqli_connect_error());
}
else{
    echo "connection successful". "<br>";
}
//insert command queary
$sql = "INSERT INTO `users` (`crno`, `name`, `age`, `salary`) VALUES ('2', 'Tejal', '22', '55000')";
    // mysqli_query($conn,$sql); // to insert a value to run this command 
    if(mysqli_query($conn,$sql))
    {
        echo "sucess";
    }
    else{
        echo "error". mysqli_error($conn);
    }
    mysqli_close($conn);

?>

this database connectivity fires the query of insert into table values 

Output:-  









Comments

Popular posts from this blog

PHP get and post method

Php basic