您需要设置几个配置文件。
/etc/odbc.ini,
/etc/odbcinst.ini而
/etc/freetds/freetds.conf(这些位置是有效的Ubuntu
12.04,并可能是正确的大多数* nixes)。
您需要安装
unixodbc和
freetds(不确定CentOS上的软件包名称是什么)。在Ubuntu中将是
apt-get installunixodbc 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 ServerDriver = freetdsDatabase = XXXXXXServerName = MSSQLTDS_Version = 7.1
/etc/odbcinst.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 TDSDriver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so#Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.soSetup = /usr/lib/i386-linux-gnu/odbc/libtdsS.soUsageCount = 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
您可能必须
tds version = 7.1根据您的MSSQL版本更改上面的行。
进行这些更改后,您将必须重新启动apache。
在您的PHP代码中,您将如下创建PDO对象:
$pdo = new PDO("dblib:host=mssql;dbname=$dbname", "$dbuser","$dbpwd");
请注意,您的用户名可能需要采用以下格式:
domainusername。
另外,如果您
phpinfo()在页面中执行并搜索“ freetds”,它将显示一个mssql部分,其中freetds列为“库版本” ,您将知道它起作用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)