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?

Recommended Answers

All 3 Replies

here,it is

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

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $sql = "INSERT INTO MyGuests (firstname, lastname, email)
    VALUES ('Nevil', 'Roy', '')";
    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, learning, and sharing knowledge.