Showing posts with label PHP IIS Windows. Show all posts
Showing posts with label PHP IIS Windows. Show all posts

Thursday, June 18, 2020

Microsoft ODBC Driver for SQL Server

Untuk connection kepada database Microsoft SQL Server di dalam Windows, Linux, & macOS perlu ada ODBC driver.  


Untuk check ODBC driver ada atau tak dalam server, tengok di sini :



ODBC driver ada banyak version, yang terkini adalah 17.

Dah install driver bolehlah buat connection, contoh connection database di dalam PHP :

### Database    ###
$user = "xx"; //database user
$pass = "xx";    //database password
$host = "xx";   //database location
$db = "xx";     //database name

$mssqldriver = '{ODBC Driver 13 for SQL Server}';

try {

$conn = new PDO("sqlsrv:Driver=$mssqldriver;Server=$host;Database=$db", $user, $pass);

} catch (PDOException $e) {

    echo $e->getMessage();
}




$conn = odbc_connect("DRIVER=SQL Server;Server=$host;Database=$db;", $user, $pass)or die("Cant connect");