douyue1998 2017-02-14 06:51
浏览 167

无法使用mysqli_connect连接到SQL Server,但MSSMS连接正常

I've read many questions similar to this but none of the answers have been relevant to me. I'm trying to access a SQL server using PHP. Both the SQL server and PHP are running on my Windows 10 machine. Here is my PHP code (the username and password are arbitrary):

$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password');

This causes the following error:

PHP Warning:  mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.

Here is my connection using MSSMS (which is successful):

Connection to 127.0.0.1 using MSSMS

EDIT:

I was able to solve my problem using this link: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/

Using this link I enable SQL Browser, and set a static port to connect to SQL server with. However, I'm presented with a new error:

PHP Warning:  mysqli_connect(): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
PHP Warning:  mysqli_connect(): Error while reading greeting packet. PID=9920 in C:\HMUAPI\Index.php on line 7
PHP Warning:  mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\HMUAPI\Index.php on line 7

My code has been changed to the following to cause this error: $connection = mysqli_connect('127.0.0.1:1434', 'hmuuser', 'password');

  • 写回答

2条回答 默认 最新

  • dsjuimtq920056 2017-02-14 06:57
    关注

    Add a database name

    $connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password','dbname');
    

    Also here is suggest - Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题