Connection php to SQL Server 2012 database from Linux

0

Good morning,

I would like to request your collaboration and knowledge with a problem that has taken me several days and from which I could not get out, I am developing an application with php but I need to connect to a MS SQL SEVER database on an external server but the problem is that my project is deployed on a linux server (Debian 9) and so far I have not managed to make the connection, neither with the PDO library, nor with the sqlsrv driver and my last attempt was through PDO_ODBC but I have not managed solve the problem.

I appreciate very much if any of you knows how I can connect effectively, thank you in advance.

    
asked by Serger 08.11.2018 в 15:20
source

1 answer

0

To connect a linux system to an SQLServer you can do it using FreeTDS

# apt-get install freetds-dev

in your /etc/freetds/freetds.conf file add the following:

[servername]
host = your.server.name
port = 1433
tds version = 8.0 

and now in your PHP file:

<?php
$conn = mssql_connect("servername", "<user>", "<password>");
 mssql_select_db( "Database1", $conn );
 $query_result = mssql_query( "SELECT field1 FROM Table1", $conn );
 echo "The field number one is: ";
 echo mssql_result ($query_result, 0, 0);
 mssql_close($conn); 
 ?>
    
answered by 10.11.2018 в 05:05