简体   繁体   English

使用PHP连接到SQL Server时出现问题

[英]Trouble connecting to SQL Server with PHP

I'm trying to connect to my local SQL Server 2008 R2 (have also tried it with 2005, same result exactly) with PHP. 我正在尝试使用PHP连接到本地SQL Server 2008 R2(在2005年也进行了尝试,结果完全相同)。 I'm using PHP 5.1 which still supports php_mssql and mssql_connect(). 我正在使用仍支持php_mssql和mssql_connect()的PHP 5.1。

for some reason PHP just won't find my server, I can connect via ODBC flawlessly an that's fine, but I would like to connect to SQL Server directly. 由于某些原因,PHP找不到我的服务器,因此我可以通过ODBC进行完美连接,这很好,但是我想直接连接到SQL Server。

I have connected PHP to SQL Server a million times on different servers, this one seems to be the only one giving me issue. 我已经在不同的服务器上将PHP连接到SQL Server一百万次,这似乎是唯一给我发出问题的服务器。

This is my little test code to try and get the connection working. 这是我的小测试代码,试图使连接正常工作。

//define connection garbage
$db['hostname'] = "USER90C6\SQLEXPRESS";
$db['username'] = "user";
$db['password'] = "password";
$db['database'] = "kal_auth";

//connection string
$conn = mssql_connect($db['hostname'], $db['username'], $db['password']);


//does it work? :o
if($conn)
{
    echo "works";
}
else 
{
    echo "fails";
}

The error this code produces: 此代码产生的错误:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server:     USER90C6\SQLEXPRESS in C:\xampp\htdocs\test.php on line 9
fails

Is there something seriously wrong with my setup? 我的设置是否存在严重问题? or am I missing something. 还是我错过了一些东西。

  • Did you enable TCP/IP on the server's configuration tool? 您是否在服务器的配置工具上启用了TCP / IP?
  • Is the firewall blocking any ports you might be using? 防火墙是否阻止了您可能正在使用的任何端口?
  • Are your MDAC (microsoft data access components) updated? 您的MDAC(Microsoft数据访问组件)是否已更新?
  • turn on mssql.secure_connection in php.ini 在php.ini中打开mssql.secure_connection

I think you don't miss anything.. Your connection string seems to be right (you receive a "Unable to connect" error..). 我认为您不会错过任何内容。您的连接字符串似乎正确(您收到“无法连接”错误。)。 In my opinion, you problem can be a version incompatibility or a user privileges mistake. 我认为您的问题可能是版本不兼容或用户权限错误。 First of all: look at DLL driver you are using in PHP and check it's compatibility with you MSSQL version. 首先:查看在PHP中使用的DLL驱动程序,并检查它与MSSQL版本的兼容性。 Maybe can be a good idea a fresh PHP install, with the latest stable release, if it is possible. 如果可能的话,重新安装最新版本的PHP可能是个好主意。 Give a look at: http://www.php.net/manual/en/mssql.requirements.php 看看: http : //www.php.net/manual/zh/mssql.requirements.php

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM