Msphpsql: Fatal error: sqlsrv_connect: Unknown exception caught (Mac OS)

Created on 25 Apr 2018  路  5Comments  路  Source: microsoft/msphpsql

+## Driver version or file name
5.2.0

+## SQL Server version
SQL Server 2017 on Docker

+## Client operating system
MacOS 10.12.6

+## PHP version
Tried both 7.0.x and 7.2.x

+## Microsoft ODBC Driver version
unixODBC 2.3.6

+## Table schema
Not apply

+## Problem description
Fatal error: sqlsrv_connect: Unknown exception caught.

+## Expected behavior and actual behavior
sqlcmd connects successfully
php driver installed correctly as i can see on phpinfo()
but i can't connect using sqlsrv or pdo.

+## Repro code
Followed example inside this tutorial: https://www.microsoft.com/en-us/sql-server/developer-get-started/php/mac/step/2.html
And this: https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017
No success.

Most helpful comment

I'm experiencing the same issue connecting to a remote sql srv 2012: adding to ~/.zshrc

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

as stated here https://github.com/Microsoft/msphpsql/issues/161#issuecomment-384662270 make the connection from cli works

All 5 comments

@luizzz Could you provide a repro script and the exact output you see so that we know exactly what you are trying to do?

Well, just tried on my MacBook Pro and works flawlessly.
Same configuration above except MacOS 10.13.4 and PHP Version 7.2.2.
On my MacOS 10.12.6 doesn't work.

Test code:

<?php
    $serverName = "187.28.xx.xxx";
    $connectionOptions = array(
        "Database" => "*********",
        "Uid" => "user_homolog",
        "PWD" => "*********"
    );
    //Establishes the connection
    $conn = sqlsrv_connect($serverName, $connectionOptions);
    if($conn)
        echo "Connected!"

Output:
Fatal error: sqlsrv_connect: Unknown exception caught on line 9

Ok, could you provide an ODBC trace for this script? To get a trace, add "TraceOn"=>true, "TraceFile"=>"trace.log" to your connection options, and add the following lines to your /etc/odbcinst.ini file:

[ODBC]
Trace=yes
TraceFile=<path to trace.log>

and run your script. Please run the trace for when it fails and when it works so we can compare the two.

I'm experiencing the same issue connecting to a remote sql srv 2012: adding to ~/.zshrc

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

as stated here https://github.com/Microsoft/msphpsql/issues/161#issuecomment-384662270 make the connection from cli works

I'm experiencing the same issue connecting to a remote sql srv 2012: adding to ~/.zshrc

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

as stated here #161 (comment) make the connection from cli works

in my case .bash_profile

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sarke picture Sarke  路  4Comments

dkrdj8989 picture dkrdj8989  路  3Comments

adankert picture adankert  路  4Comments

arunchandarQA picture arunchandarQA  路  3Comments

Grglrglrg picture Grglrglrg  路  4Comments