Javascript AJAX jQuery HTML OOPS PHP PHP Example MORE

Retrieve Data from MySQL Using PHP OOPS Concept

For retrieve data from MySQL first we have to create a table in data base.

Here we using 2 file For retrieve data from MySQL:

Crud.php:For connecting data base and function

view.php:For get the data and show in a table

CREATE TABLE `employee` (
	`userid` int(8) NOT NULL AUTO_INCREMENT,
	`first_name` varchar(55) NOT NULL,
	`last_name` varchar(55) NOT NULL,
	`city_name` varchar(55) NOT NULL,
	`email` varchar(50) NOT NULL,
    `datetime` datetime NOT NULL


    class Crud
        private $servername = "localhost";
		private $username   = "root";
		private $password   = "";
		private $dbname = "oops_db";
        public $con;
        public $employeeTable = "employee";
		public function __construct()
			try {
				$this->con = new mysqli($this->servername, $this->username, $this->password, $this->dbname);	
			} catch (Exception $e) {
				echo $e->getMessage();
        /* Fetch employee records for show listing */
		public function displayRecord()
			$sql = "SELECT * FROM $this->employeeTable";
			$query = $this->con->query($sql);
			$data = array();
			if ($query->num_rows > 0) {
				while ($row = $query->fetch_assoc()) {
					$data[] = $row;
				return $data;
				return false;


<!DOCTYPE html>
<html lang="en">
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
$viewdata=new Crud();  
$customers = $viewdata->displayRecord();
$output ="";
$output .="<table class='table table-striped table-hover'>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>City Name</th>
    foreach ($customers as $customer) {
$output .= "</tbody>
echo $output;