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

While I would have stuck with MySQL that's in WAMP, it appears that setup for WAMP 3 with MS SQL is a lot more work. Check that you got it all done by reading

Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.