1. First, install the PHP PDO_ODBC module in EA4.

2. Then we have to install Microsoft SQL Server ODBC Driver for Linux, download available at https://www.microsoft.com/en-us/download/details.aspx?id=28160

3. Following the instructions to install it and restart Apache and edit the file /etc/odbc.ini with this config:

[MSSQLServer]
Driver = SQL Server Native Client 11.0 Description = Database access Trace = No Server = 123.456.789.0 Port = 1433 Database = DatabaseName

Then on the PHP script add the following to connect to the database like this: 

<?php 

putenv('ODBCSYSINI=/etc/'); 

putenv('ODBCINI=/etc/odbc.ini'); 

try { 

    $db = new PDO("odbc:MSSQLServer", $username, $password); 

  } catch (PDOException $exception) { 

    echo $exception->getMessage(); 

    exit; 

} 

$q = $db->query("SELECT * from Table"); 

while ( $d = $q->fetchObject() ) { 

var_export( $d ); 

}
Was this answer helpful? 2 Users Found This Useful (72 Votes)