how to connect ms sql server in pdo code example
Example 1: how to connect pdo php database
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
Example 2: php pdo sql server connect
$db = new PDO("sqlsrv:Server=YouAddress;Database=YourDatabase", "Username", "Password");