问题描述
我已经安装在我的Mac freetds的,但我在使用连接的一些问题 mssql_connect
。
I have installed FreeTDS on my Mac, but I'm having some issues connecting using mssql_connect
.
首先,当我运行TSQL -C我看到freetds.conf目录被列为 /选择/本地/ etc / freetds的
。我有这个目录里面freetds.conf文件。
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');
然后一切按预期工作。也就是说,我可以检索,更新,从/将数据插入我与选择任何DB mssql_select_db()
。
如果我尝试连接这样的:
If I try to connect like this:
$connect = mssql_connect('DSN_NAME', 'username', 'password');
其中, DSN_NAME
在我的freetds.conf文件中指定的话,我得到一个错误的数据源和无法连接到服务器匹配:DSN_NAME
这告诉我,PHP没有正常看到路径,我freetds.conf文件。
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");
然后一切按预期工作。这告诉我,我的freetds.conf文件格式正确无误。
then everything works as expected. This tells me that my freetds.conf file is formatted correctly.
我已经找遍了有关如何找到PHP的认为的的freetds.conf文件,但是我无法找到。
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.
最后,还有一些原因,我不想直接在我的连接使用的IP地址以及为什么我不希望被迫使用 putenv()函数
方法来指定目录。
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.
任何想法?
感谢您。
推荐答案
当我安装freetds的我最初使用的MacPorts。我认为,这给了我在那里freetds.conf本来应该有的冲突。而且即使对于freetds.conf路径运行时, TSQL -C
是,我尝试使用的实际路径,当我编译该路径的PHP扩展mssql.so就认不出来了。
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.
解决方案是忘记freetds的MacPorts的,只是从源代码安装freetds的。然后安装从PHP源mssql.so扩展,并确保您使用的是系统上的相同版本(我的是在OS X山狮5.3.13)。
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 http://blog.benjaminwalters.net/?p=10 exactly you shouldn't have any issues.
一对夫妇的最后的东西:
A couple of final things:
- 我不跑MAMP即使说明书提到它,所以它不会不管两种方式。
- 如果你已经没安装使用通过的MacPorts,卸载freetds的:
sudo的港口卸载freetds的+ ODBC
然后sudo的港口卸载的unixODBC
。请确保您卸载freetds的所有实例。如果你有一个以上的,你会得到一个通知,当你运行你需要指定版本卸载卸载。
- 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 thensudo 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.
这篇关于使用MSSQL的方法(freetds的,PHP和Apache在Mac OS X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!