1

I am having trouble in Connecting to SQL Server remotely from PHP/Ubuntu 20.

Currently My PHP version is PHP7.4.I used this document to install the ODBC Driver

https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-on-ubuntu (I have replaced the php version to 7.4 wherever it was 8.0).

Restarted the server and checked PHP Info. Seems its installed check screenshot

enter image description here enter image description here

Now I am trying to connect to SQL Server. The SQL Server Access was given in IP, Username and Password. I am able to connect to database from HeidiSQL tool.

When I connect through PHP Code:

$conn = new PDO("sqlsrv:Server=". $serverName .";Database=". $databaseName, $uid, $pwd);

or

$serverName = "xxx.xxx.xxx.xxx";
$connectionOptions = array(
    "database" => "<mydbname>",
    "uid" => "<dbusername>",
    "pwd" => "<dbpass>"
);
$conn = sqlsrv_connect($serverName, $connectionOptions);

both given me error:

SQLSTATE: 08001
Code: 10054
Message: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746

Can anyone help in I don't know what I should follow. Is something I need to check on installation side, I mean on Ubuntu server or I should ask to SQL Server provider if they need to do something on their end.

2
  • Since it's a remote server, and possibly sitting behind a firewall, can you telnet to the server on tcp/1433? Commented Aug 31, 2021 at 4:10
  • make sure you follow learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/… Very easy to miss that little block in the guide Commented Aug 31, 2021 at 11:23

1 Answer 1

1

Its too late. Anyway I am answering my own question for someone who face same issue again. I have resolved this by installing an OpenSSL on the server.

Follow these steps for installation

https://help.dreamhost.com/hc/en-us/articles/360001435926-Installing-OpenSSL-locally-under-your-username

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.