我需要在Ubuntu上连接到PHP的MS SQLServer 2008服务,我想这样做使用PDO。我相信我已经安装了所有先决条件库,并且我确实能够在命令行上使用tsql
进行连接,并在代码中使用mssql_connect()
。我无法弄清楚正确的DSN是什么,或者是否缺少任何其他PDO特定的配置步骤。PHP通过PDO从Linux连接到MS SQLServer 2008
我使用下面的DSN(其中$db*
变量填入相应的值):
odbc:Driver=FreeTDS;SERVER=$dbServer;DATABASE=$dbSchema;UID=$dbUser;PWD=$dbPasswd"
我的错误信息是:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /home/timothy/test.php:4
Stack trace:
#0 /home/timothy/test.php(4): PDO->__construct('odbc:Driver=Fre...')
#1 {main}
thrown in /home/timothy/test.php on line 4
什么额外的配置步骤都我漏掉了?
在此先感谢。
在你的php.ini中设置了什么? 'mssql.secure_connection'如果打开并重新测试。请确保重新启动Apache以及 – 2010-11-02 14:31:27
mssql.secure_connection已关闭。但请记住mssql_ *函数的工作原理,我只是试图使用PDO接口。 – Timothy 2010-11-02 15:20:03