我正在使用Xampp与Php 5.4(Zend studio)并下载sqlserver驱动程序下载V3.0 for php 5.4
我跟着this URL。
我配置了URL以上的所有步骤,但我仍然无法连接打开并出现错误..
Connection could not be established.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 53 [code] => 53 [2] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. [message] => [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 53 [code] => 53 [2] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct enter code here and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ))
请为上述问题提供解决方案。
答案 0 :(得分:0)
转到“开始”\“Microsoft SQL Server 2008”\“配置工具”\“SQL Server配置管理器”,然后转到“SQL本机客户端配置”,“客户端协议”,并检查是否已启用共享内存,tcp / ip和命名管道。
我写这个作为答案,因为我还不能发表评论。
答案 1 :(得分:0)
(不要意味着复活一篇旧帖子,但以防其他人正在寻找答案,因为这篇文章是在我的搜索过程中出现的......)
使用本机驱动程序从XAMPP上的PHP连接到SQL_server的简短分步指南:
首先从http://www.microsoft.com/en-us/download/details.aspx?id=20098下载PHP for SQL_server Microsoft本机驱动程序。请注意选择适合您设置的驱动程序。
将其安装到PHP扩展目录(通常位于c:\xampp\php\ext
)。
通过取消注释或附加该行(取决于所选择的驱动程序版本),在PHP.ini
中配置新扩展名(通常在C:\xampp\php
中)。即:
extension = php_sqlsrv_55_ts.dll
从XAMPP控制面板重启Apache(停止+启动)。
现在,您的PHP设置可以连接到SQL_server数据库。调整以下代码以使用您自己的数据库对其进行测试:
<?php
$server = "SERVER\SQLEXPRESS";
$database = "test_database";
$user = "test_user";
$pwd = "test_password";
$options = array( "UID" => $user, "PWD" => $pwd, "Database" => $database);
$conn = sqlsrv_connect($server, $options);
if ($conn === false) {
die("<pre>".print_r(sqlsrv_errors(), true));
}
echo "Successfully connected!";
$sql = "SELECT TOP 50 * FROM dbo.table_name";
$query = sqlsrv_query($conn, $sql);
if ($query === false) {
exit("<pre>".print_r(sqlsrv_errors(), true));
}
while ($row = sqlsrv_fetch_array($query)) {
echo "<p>$row[field1] $row[field2]</p>";
}
sqlsrv_free_stmt($query);
sqlsrv_close($conn);
在SQL_server 2008 R2和SQL_server 2014 express上从XAMPP 3.2.1和XAMPP 5.6.14进行测试。