[php] code php connect mssql

Code mẫu

<?php
$serverName = "IP_Server"; // ví dụ: '123.123.123.123'
$database = "databasename";
$username = "user_connect_database";
$password = "password_user_database";

try{

$connectionInfo = new PDO("sqlsrv:Server={$serverName};Database=".$database.'&charset=utf8', $username, $password);
$connectionInfo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}


?>
Bình luận