<audio controls autoplay unmuted>
<source src="horse.ogg" type="audio/ogg">
<source src="Image/xxx.mp3" type="audio/mpeg">
</audio>
or
<embed src="Image/xxx.mp3" loop="true" autostart="true" width="0" height="0">
<audio controls autoplay unmuted>
<source src="horse.ogg" type="audio/ogg">
<source src="Image/xxx.mp3" type="audio/mpeg">
</audio>
or
<embed src="Image/xxx.mp3" loop="true" autostart="true" width="0" height="0">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ Index.php [L]
DB.php :
<?php
class DbConnect {
private $server = 'localhost';
private $dbname = 'hanuman';
private $user = 'root';
private $pass = '';
public function connect() {
try {
$conn = new PDO('mysql:host=' .$this->server .';dbname=' . $this->dbname, $this->user, $this->pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
} catch (\Exception $e) {
echo "Database Error: " . $e->getMessage();
}
}
}
?>
Index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Max-Age: 3600");
include("DB.php");
$dbConnect = new DbConnect();
$conn= $dbConnect->connect();
$method=$_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'GET' :
$sql="select * from emp";
$path=explode('/',$_SERVER['REQUEST_URI']);
if(isset($path[2]) && is_numeric($path[2])){
$sql .=" where eid =:eid order by eid desc";
$stmt = $conn->prepare($sql);
$stmt ->bindParam(':eid',$path[2]);
$stmt->execute();
$emp= $stmt->fetch(PDO::FETCH_ASSOC);
}else {
$stmt=$conn->prepare($sql);
$stmt->execute();
$emp= $stmt->fetchAll(PDO::FETCH_ASSOC);
}
echo json_encode($emp);
break;
case 'POST':
$emp= json_decode(file_get_contents('php://input'));
$sql="INSERT INTO `emp`(`NAME`, `ADDRESS`) VALUES (:name,:address)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':name',$emp->name);
$stmt->bindParam(':address',$emp->address);
if($stmt->execute()) {
$response= ['status' =>200, 'message' => 'Data Saved.'];
}
else {
$response= ['status' =>500, 'message' => 'Internal server error.'];
}
return json_encode($response);
break;
case 'PUT':
$emp= json_decode(file_get_contents('php://input'));
$sql="UPDATE emp SET NAME=:name,ADDRESS=:address WHERE EID=:eid";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':eid',$emp->eid);
$stmt->bindParam(':name',$emp->name);
$stmt->bindParam(':address',$emp->address);
if($stmt->execute()) {
$response= ['status' =>200, 'message' => 'Data Updated.'];
}
else {
$response= ['status' =>500, 'message' => 'Internal server error.'];
}
return json_encode($response);
break;
case 'DELETE':
$path=explode('/',$_SERVER['REQUEST_URI']);
$sql="delete from emp where eid=:eid";
$stmt = $conn->prepare($sql);
$stmt ->bindParam(':eid',$path[2]);
if($stmt->execute()) {
$response= ['status' =>200, 'message' => 'Data deleted.'];
}
else {
$response= ['status' =>500, 'message' => 'Internal server error.'];
}
break;
default:
echo 'Something went wrong.';
break;
}
?>