IODBC error when trying to connect to MS SQL Server in PHP using unixODBC / FreeTDS

I am trying to connect to a remote MS SQL Server db from PHP on a Mac (ending up on an Ubuntu server (with FreeTDS and unixODBC, but even if everything is configured correctly, I get iODBC errors and I'm not sure how to get around them.

I use MacPorts, so my configuration is:

/opt/local/etc/freetds.conf ::

[bti_db]
host = 123.45.67.89 (IP address changed to protect the innocent)
port = 14333
tds version = 8.0

/opt/local/etc/odbcinst.ini:

[FreeTDS]
Description = TDS Driver (Sybase/MSSQL)
Driver = /opt/local/lib/libtdsodbc.so
Setup = /opt/local/lib/libtdsS.so
FileUsage = 1

/opt/local/etc/odbc.ini:

[bti_dsn]
Driver = FreeTDS
Description = My Database
Trace = no
Servername = bti_db
Database = btidata

However, when I try to connect to odbc_connect () using 'bti_dsn'

$conn = odbc_connect('bti_dsn;, $user, $pw);

I get this error:

Warning: odbc_connect () [function.odbc-connect]: SQL error: [iODBC] [Driver Manager] No data source name was found and no default driver was specified. Driver cannot be loaded, SQL state IM002 in SQLConnect

ODBC my phpinfo() ODBC, iodbc, PHP '--with-iodbc =/usr', , . , unixODBC/FreeTDS, ?

.

+3
2

iODBC Mac OS X; Jaguar (10.2.x). UnixODBC Mac, , . PHP iODBC Mac OS X. iODBC Mac OS X.

/opt/local/etc $PATH, .profile .

PHP iODBC UnixODBC, ; UnixODBC iODBC ( ) API- ODBC. , $DYLD_LIBRARY_PATH (Mac OS X Linux $LD_LIBRARY_PATH), PHP iODBC Framework, dylib, .

( , $DYLD_LIBRARY_PATH /opt/local/lib, FreeTDS .)

- PHP , ODBC Mac ( /Library/ODBC/odbc[inst].ini; ~/Library/ODBC/odbc[inst].ini... ~/.odbdc[inst].ini, ~/Library/ODBC/ ).

iODBC , $ODBCINI odbc.ini, DSN, $ODBCINSTINI odbcinst.ini, , .

, , , , *.php ( require include ) -

putenv("DYLD_LIBRARY_PATH=/path/to/odbcsdk/lib;$DYLD_LIBRARY_PATH");
putenv("ODBCINSTINI=/path/to/odbcinst.ini");
putenv("ODBCINI=/path/to/odbc.ini");

DYLD_LIBRARY_PATH, , UnixODBC. , iODBC, , , FreeTDS , :

putenv("DYLD_LIBRARY_PATH=/opt/local/lib;$DYLD_LIBRARY_PATH");
putenv("ODBCINSTINI=/opt/local/etc/odbcinst.ini");
putenv("ODBCINI=/opt/local/etc/odbc.ini");

, .

P.S. DSN -

Driver = FreeTDS

- . ({FreeTDS}), (/opt/local/lib/libtdsodbc.so) .

Driver = {FreeTDS}
Driver = /opt/local/lib/libtdsodbc.so

, - odbcinst.ini -

[ODBC Drivers]
FreeTDS = Installed

- - odbc.ini -

[ODBC Data Sources]
bti_dsn = FreeTDS

... , $conn . odbc_connect.

$conn = odbc_connect('bti_dsn;, $user, $pw);

,

$conn = odbc_connect("bti_dsn", "$user", "$pw");
+6

, odbc.ini. , /etc/odbc.ini /etc/odbcinst.ini?

0

Source: https://habr.com/ru/post/1754744/


All Articles