dpwbc42604 2014-09-13 23:58
浏览 53

无法使用php连接到localhost SQL Server 2012

Hi I have a big problem with php connection to my local database.

I'm running: Windows Server 2008 sp 1. SQL server 2012. My SQL server name: LRE-XP-VS2003\SQLEXPRESS. (status is running)

This is how I'm trying to connect

$server = 'localhost'; //or 127.0.0.1
$login = 'sa';
$passwd = 'my_passwd';
$database = 'ms4033';
$port = '49717';

$con = mysqli_connect ( $server , $login, $passwd, $database, $port );

if (!$con) {
  die("Connection error: " . mysqli_connect_errno());
 }

Result I get is spinning the loading button in browser and after long time "Internal Server Error - The FastCGI process exceeded configured activity timeout"

For the port number I checked in HKEY_LOCAL_MACHINE and also directly in database

 USE master
 GO
 XP_READERRORLOG 0, 1, N'Server is listening'
 GO

and in SQL server Configuration manager too. Without port number I get "No connection could be made because the target machine actively refused it" or "Connection error: 2002"

I tried diseable my Firewall and it did not help.

I'm running asp .net too and paradoxically the connection is working properly with this:

<add key="connectionString" value="server=LRE-XP-VS2003\SQLEXPRESS;database=ms4033;packet size=4096;user id=sa;password=my_passw" />

Am I missing something?

And what's difference between $server = 'localhost'; or $server = 'LRE-XP-VS2003\SQLEXPRESS'; ?

Thanks a lot.

  • 写回答

1条回答 默认 最新

  • dongyipa0028 2014-09-14 00:02
    关注

    Check this article. You need to use MS SQL connection, not the MYSQL

    <?php
    // Server in the this format: <computer>\<instance name> or 
    // <server>,<port> when using a non default port number
    $server = 'KALLESPC\SQLEXPRESS';
    
    // Connect to MSSQL
    $link = mssql_connect($server, 'sa', 'phpfi');
    
    if (!$link) {
        die('Something went wrong while connecting to MSSQL');
    }
    ?>* 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作