How to insert data in sql server 2012 express using php pdo in wamp server 3? What connection string I need to use to connect in the database?

here,it is

<?php
$servername = "localhost";
$username = "username";
$password = " ";
$dbname = " ";//your database name

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO MyGuests (firstname, lastname, email)
    VALUES ('Nevil', 'Roy', 'nevilroy@example.com')";
    $conn->exec($sql);
    echo "Record Inserted successfully";
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }

$conn = null;
?>

$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

He asked for Microsoft SQL Server, not MySQL

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.