php mssql 调用odbc,通过PDO ODBC将PHP连接到MSSQL

fdc2fafd29314ec94e869905aa0e7ae9.png

慕工程0101907

您需要设置几个配置文件。/etc/odbc.ini,/etc/odbcinst.ini而/etc/freetds/freetds.conf(这些位置是有效的Ubuntu 12.04,并可能是正确的大多数* nixes)。您需要安装unixodbc和freetds(不确定CentOS上的软件包名称是什么)。在Ubuntu中将是apt-get install unixodbc tdsodbc。如需安装这些软件的帮助,请查看此问题。无法通过Yum Package Manager安装FreeTDS/etc/odbc.ini(此文件可能为空)# 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 = #       port = #       tds version = # 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");请注意,您的用户名可能需要采用以下格式:domain\username。此外,如果您phpinfo()在页面中执行并搜索“ freetds”,它将显示一个mssql部分,其中freetds列为“库版本” ,您将知道它起作用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值