W
W
winmasta2017-06-07 12:42:00
PHP
winmasta, 2017-06-07 12:42:00

How to connect to MSSQL from PHP7.0?

Configured PHP according to this https://stackoverflow.com/questions/34377338/linux... instructions (I only had to add .so to the file names in the config).
Wrote a simple code

$serverName = "192.168.1.1\INSTANCENAME";
$connectionInfo = array("Database"=>"DBNAME", "UID"=>"user", "PWD"=>"password");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$sql = "select * from table";
$stmt = sqlsrv_query($conn, $sql);
print_r($stmt);
sqlsrv_close($conn);

When executed, it hangs for a long time, nothing happens, then it stops.
Meanwhile, this line
sqlcmd -S 192.168.1.1 -d DBNAME -U user -P password -Q "select * from table"
executed from the same machine where nginx+php is installed gives the desired result.
I checked that the packets go in both cases, only in the first one the first one comes and then only the keepalive falls, in the second case everything is as it should be. Tell me where is the problem? Maybe there are other PHP7 + mssql options?
PS while writing, I decided to check this option
$serverName = "192.168.1.1";
, then the question is transformed, how to connect to different instances of the server?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Axian Ltd., 2017-06-07
@winmasta

Different copies hang on different ports.

K
Konstantin, 2017-06-07
@kostya_vtomske

$link = mssql_connect('ip', 'user', 'pass');
mssql_select_db('bd, $link);
mb_internal_encoding('utf8');
Doesn't work in branch 7?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question