使用PHP中的PDO_MSSQL连接到SQL Server [英] Connecting to SQL Server with PDO_MSSQL in PHP
本文介绍了使用PHP中的PDO_MSSQL连接到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试通过以下行使用pdo_mssql连接到我的SQL Server 2000数据库时出现问题:
I have a problem while trying to connect to my SQL Server 2000 database using pdo_mssql with this line:
$connection = new PDO ('mssql:host=localhost;dbname=DNAME', 'user', 'password');
例外情况如下:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server. (severity 5)' in C:\Inetpub\wwwroot\public\test.php:2 Stack trace: #0 C:\Inetpub\wwwroot\public\test.php(2): PDO->__construct('mssql:host=loca...', 'user', 'password') #1 {main} thrown in C:\Inetpub\wwwroot\public\test.php on line 2
如果按如下所示使用函数mssql_connect()建立连接,则不会出现错误,并且连接正确:
If I make the connection using the function mssql_connect() as follows, I obtain no error and my connection is correctly made:
$link = mssql_connect ('localhost', 'user', 'password');
有什么主意吗?在哪里可以阅读详细的错误消息?谢谢
Any idea? Where can I read the detailed error message? Thanks
推荐答案
我的数据库名称使用字符-",将其删除即可解决问题!
My database name had the character "-", removing it solved the problem!
这篇关于使用PHP中的PDO_MSSQL连接到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文