php fetch all data code example

Example 1: how to fetch data from database in php

<?php
  ////////////neha jaiswal///
$serve="localhost";
$user="root";
$password="";
$db="neha";
$con=mysqli_connect($serve,$user,$password,$db);
 if ($con) {
 echo "connection success"; 
 }else
{echo "connection unsuccess"; }
 $query="SELECT * FROM product";
 $result=$con->query($query);
 if($result->num_rows>0){
 	while($row=$result->fetch_assoc())
 	{
 		echo $name=$row['name'];
 		echo $qty=$row['qty'];
 		echo	$price=$row['price'];
 		echo	$image=$row['image'];
 	}
 }

?>

Example 2: php code for fetching data from database

CREATE DATABASE company;
CREATE TABLE employee(
employee_id int(10) NOT NULL AUTO_INCREMENT,
employee_name varchar(255) NOT NULL,
employee_email varchar(255) NOT NULL,
employee_contact varchar(255) NOT NULL,
employee_address varchar(255) NOT NULL,
PRIMARY KEY (employee_id)
)
Copy

Tags:

Php Example