<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;
}
?>
Web Api Code:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace WebApplication4.Models
{
public class EMP
{
[Key]
public int Eid { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
}
---
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace WebApplication4.Models
{
public class AppdbContext:DbContext
{
public AppdbContext() : base("name=AppDbConnection")
{
}
public DbSet<EMP> Emps { get; set; }
}
}
--
In web.config file u add the connection string
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="AppDbConnection" connectionString="Data Source=(localdb)\ProjectsV13;Initial Catalog=Mahadev;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration>
Configuration
class.Up()
and Down()
methods.Add-Migration
command and applies changes to the database schema.IIn order to create a Web API client.
Add Microsoft.AspNet.Webapi.Client using NuGet package manager.