本文介绍了如何从具有PHP PDO的Mac连接到Sql Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在Google上搜索此问题,则会发现许多错误,误导和过时的信息.令人惊讶的是,Stack Overflow没有一个可靠的答案,因此我们应该更改它.

If you search Google for this question, you will find a lot of incorrect, misleading, and outdated information. Surprisingly, there isn't a solid answer on Stack Overflow, so we should change that.

我正在使用Apache和PHP的Mac端口安装.我已经安装了php5-mssql,在phpinfo()页面上可以看到mssql.

I am using the Mac port installation of Apache and PHP. I have installed php5-mssql, and I can see mssql on my phpinfo() page.

但是我没有在PDO中看到它.

But I don't see it listed under PDO.

PDO support enabled
PDO drivers     dblib, mysql, odbc, pgsql 

mssql是否不与PDO关联?在Mac上是否可以使用PDO将另一个驱动程序连接到SqlServer数据库?似乎这应该是可能的.

Is mssql not associated with PDO? Is there another driver that can be used on a Mac to connect to a SqlServer database using PDO? Seems like this is something that should be possible.

推荐答案

这对您有帮助吗?

http://blog.nguyenvq.com/2010 /05/16/freetds-unixodbc-rodbc-r/

我使用FreeTDS从Linux服务器连接到Microsoft SQL服务器,看起来上面链接中的人已经使用FreeTDS从Mac连接.

I use FreeTDS to connect to Microsoft SQL servers from a Linux server and it looks like the person in the link above has used FreeTDS to connect from a Mac.

这是我的/etc/freetds/freetds.conf文件(我添加的唯一部分是在XYZ服务器的最后):

Here is my /etc/freetds/freetds.conf file (the only part I added was at the very end for the XYZ server):

[global]
        # TDS protocol version
;       tds version = 4.2

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.  
        # Try setting 'text size' to a more reasonable limit 
        text size = 64512

# Define a connection to the MSSQL server.
[xyz]
        host = xyz
        port = 1433
        tds version = 8.0

[由提问者编辑]

FreeTDS配置是答案的前半部分.配置完成后,您应该可以从命令行运行类似的内容并连接:

FreeTDS configuration is the first half of the answer. Once it's configured you should be able to run something like this from the command line and connect:

tsql -S xyz -U username -P password

然后,您需要使用dblib而不是mssql作为PDO驱动程序:

Then you need to use dblib, not mssql, as the PDO driver:

$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname",
                "$dbuser","$dbpwd");

$ dbhost是freetds.conf文件中的名称

Where $dbhost is the name from the freetds.conf file

这篇关于如何从具有PHP PDO的Mac连接到Sql Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:39