我已经阅读了许多类似的问题,但没有一个答案与我有关。我试图使用PHP访问SQL服务器。 SQL服务器和PHP都在我的Windows 10计算机上运行。这是我的PHP代码(用户名和密码是任意的):
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password');
这会导致以下错误:
PHP Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
这是我使用MSSMS的连接(成功):
编辑:
我能够使用此链接解决我的问题:http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/
使用此链接启用SQL Browser,并设置静态端口以连接到SQL Server。但是,我提出了一个新错误:
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
我的代码已更改为以下内容导致此错误:$connection = mysqli_connect('127.0.0.1:1434', 'hmuuser', 'password');
答案 0 :(得分:0)
添加数据库名称
$child_name=$_POST['child'];
$count=count($child_name);
for ($i=0; $i < $count ; $i++) {
$child_bday=date('Y-d-m', strtotime($_POST['ch_DateOfBirth'][$i]));
$sql6="INSERT into tbl_children (Emp_ID, Ch_Name, Ch_Bdate) values ('".$emp_id."', '".$child_name[$i]."', '".$child_bday."') ";
$dbcon->query($sql6);
}
同样here is建议 - 主动拒绝它“意味着当您尝试连接时主机发送了重置而不是确认。因此,您的代码中没有问题。是否有防火墙阻止连接或者托管该服务的进程没有侦听该端口。这可能是因为它根本没有运行,或者因为它正在侦听不同的端口。
答案 1 :(得分:0)
我想问题是,您使用MySQLi连接到MSSQL服务器。
您应该使用正确的MSSQL扩展名。 Microsoft在GitHub上发布了他们的SQL-Server for PHP驱动程序:https://github.com/Microsoft/msphpsql 或者您使用PHP手册中记录的旧扩展程序:http://de2.php.net/manual/en/book.mssql.php 至少你可以设置ODBC。
其中一个应解决您的问题。