설정해야하는 몇 가지 구성 파일이 있습니다. /etc/odbc.ini
, /etc/odbcinst.ini
및 /etc/freetds/freetds.conf
(이 위치는 Ubuntu 12.04에 유효하며 대부분의 * nixes에 적합 할 수 있음).
unixodbc
및 freetds
(패키지 이름이 CentOS에 있는지 확실하지 않음)을 설치해야합니다. 우분투에서는 apt-get install unixodbc tdsodbc
이됩니다. 이러한 설치에 대한 도움말
이 질문에
# Define a connection to a Microsoft SQL server
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssql]
Description = MSSQL Server
Driver = freetds
Database = XXXXXX
ServerName = MSSQL
TDS_Version = 7.1
/etc/odbcinst.ini Can't Install FreeTDS via Yum Package Manager
/etc/odbc.ini (이 파일이 비어있을 수 있습니다)를 볼
# Define where to find the driver for the Free TDS connections.
# Make sure you use the right driver (32-bit or 64-bit).
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
#Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
/etc/freetds/freetds.conf (또는 /etc/freetds.conf에서 찾을 수 있습니다)
# The basics for defining a DSN (Data Source Name)
# [data_source_name]
# host = <hostname or IP address>
# port = <port number to connect to - probably 1433>
# tds version = <TDS version to use - probably 8.0>
# Define a connection to the Microsoft SQL Server
[mssql]
host = XXXXXX
port = 1433
tds version = 7.1
MSSQL의 버전에 따라 위의 tds version = 7.1
행을 변경해야 할 수도 있습니다.
변경 한 후에 아파치를 다시 시작해야합니다. PHP 코드에서
이처럼 PDO 개체를 만듭니다 : 사용자 이름의 형식에 있어야합니다
$pdo = new PDO("dblib:host=mssql;dbname=$dbname", "$dbuser","$dbpwd");
참고 : domain\username
합니다.
또한 페이지에서 phpinfo()
을 실행하고 freetds가 라이브러리 버전으로 나열된 mssql 섹션을 표시하는 "freetds"를 검색하면 작동한다는 것을 알 수 있습니다.
사용중인 운영 체제 (및 버전)는 무엇입니까? –
내 PHP는 CentOS Linux (mediatemple)에 있지만 MSSQL 데이터베이스는 Microsoft Dynamics (Great Plains)에서 제공됩니다. 나는 그것이 어떤 버전인지 모른다. 알아 내야합니까? 데이터베이스 사용자는 읽기 액세스 권한 만 가지고 있다고 나에게 말했다. – user1477388