Using mssql methods (FreeTDS, PHP and Apache on Mac OS X)

北慕城南 提交于 2020-01-14 14:17:11

问题


I have installed FreeTDS on my Mac, but I'm having some issues connecting using mssql_connect.

First, when I run tsql -C I see that the freetds.conf directory is listed as /opt/local/etc/freetds. I have a freetds.conf file inside this directory.

Next, if I connect like this:

$connect = mssql_connect('IP_ADDRESS', 'username', 'password');

then everything works as expected. That is, I can retrieve, update, insert data from/into whichever DB I select with mssql_select_db().

If I try to connect like this:

$connect = mssql_connect('DSN_NAME', 'username', 'password');

where DSN_NAME matches a datasource specified in my freetds.conf file then I get an error and unable to connect to server: DSN_NAME which tells me that PHP isn't correctly seeing the path to my freetds.conf file.

However, if before my call I add:

putenv("FREETDSCONF=/opt/local/etc/freetds/freetds.conf");

then everything works as expected. This tells me that my freetds.conf file is formatted correctly.

I've searched all over about how to find the path that PHP thinks the freetds.conf file is in, but I can't find that.

Lastly, there are some reasons I don't want to use the IP address directly in my connection as well as why I don't want to be forced to use the putenv() method to specify the directory.

Any ideas?

Thank you.


回答1:


When I installed FreeTDS I originally used MacPorts. I believe that this gave me some conflicts for where freetds.conf should have been. And even though the path for freetds.conf when running tsql -C was the actual path that I was attempting to use, when I compiled the mssql.so extension with that path PHP wouldn't recognize it.

The solution is to forget MacPorts for FreeTDS and just install FreeTDS from source. Then install the mssql.so extension from the PHP source and make sure you're using the same version that is on your system (mine was 5.3.13 under OS X Mountain Lion).

If you follow the instructions at this blog exactly you shouldn't have any issues.

A couple of final things:

  • I am NOT running MAMP even though the instructions mention it so it won't matter either way.
  • If you already did install FreeTDS via MacPorts, uninstall using: sudo port uninstall freetds +odbc and then sudo port uninstall unixODBC. Make sure you uninstall all instances of FreeTDS. If you have more than one, you'll get a notice when you run uninstall that you need to specify the version to uninstall.


来源:https://stackoverflow.com/questions/11846438/using-mssql-methods-freetds-php-and-apache-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!