0

I'm trying to connect to a MSSQL database with odbc in php. My issue is similar to this issue, I can connect with tsql, but not with php. The answer to the problem not work because I think I don't have SELinux installed (I don't know what it is, but pacman not found this package (or with a similar name) on my computer) I don't understand why it doesn't work, odbc is installed and detected by php

print_r(PDO::getAvailableDrivers()); 
Array ( [0] => odbc )

I'm connecting by doing that:

$dsn = 'odbc:Driver=FreeTDS;Server=127.0.0.1;Port:1433;Database=[my base name]';
$pdo = new PDO($dsn, $user, $password);

My base is not in local, I use a ssh tunel because the base in accessible only at my school, and we need an ssh tunnel. And it work, I can connect myself to the base with tsql.

vixa
  • 33
  • 4

1 Answers1

0

When I was connecting PHP to our MS SQL server, I could never get a connection established using ODBC drivers.

Instead, I downloaded the official PHP > SQL SERVER drivers direct from Microsoft. You can find them here.

Once installed, you must configure your php.ini file to include the new drivers, restart your web server and then use the following to open a new connection:

$conn = new PDO("sqlsrv:Server=SERVER_IP,1433;Database=DATABASE_TO_OPEN;");
Mark
  • 691
  • 7
  • 20
  • Thank you for responding I don't have ubuntu or red hat, I am running manjaro linux, and microsoft's drivers seems to not exist on arch/manjaro. – vixa Sep 27 '18 at 13:51