简体   繁体   English

为什么我不能使用PHP连接到Sql Server?

[英]Why can't I connect to a Sql Server with PHP?

I wrote code as below: 我写的代码如下:

<?php
    $conn = mssql_connect("xx.xx.xx.xx", "username", "password") 
            or die("Can't connect to server ".mssql_error());
    echo "Success";
    mssql_close($conn);
?>

The error is: 错误是:

PHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xx.xx.xx.xx in xxxxxxx\\conn.php on line 2 PHP Fatal error: Call to undefined function mssql_error() in xxxxxxx\\conn.php on line 3 PHP警告:mssql_connect()[function.mssql-connect]:无法连接到服务器:第2行的xxxxxxx \\ conn.php中的xx.xx.xx.xx PHP致命错误:调用xxxxxxx \\中未定义的函数mssql_error()第3行的conn.php

The server is Apache2.2, the version of Sql Server is 2005, the version of PHP is 5.2.5, and I remove the ; 服务器是Apache2.2,Sql Server的版本是2005,PHP的版本是5.2.5,我删除了; before extension=php_mssql.dll and there is a php_mssql.dll in the ext directory extension=php_mssql.dll之前,并且ext目录中有一个php_mssql.dll

Use mssql_get_last_message() 使用mssql_get_last_message()

<?php
    $conn = mssql_connect("xx.xx.xx.xx", "username", "password") 
            or die("Can't connect to server ".mssql_get_last_message());
    echo "Success";
    mssql_close($conn);
?>

服务启动时,是否可以检查apache日志中mssql扩展是否有问题?

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

相关问题 为什么我无法连接到SQL Server? - Why can't I connect to my SQL Server? 为什么我无法连接到mssql服务器? (PHP) - Why can't I connect to mssql server? (PHP) PHP无法连接到SQL Server - PHP can't connect to SQL Server 无法从 PHP 连接到 SQL Server - Can't connect to SQL Server from PHP 为什么我可以从PHP连接到本地SQL Server Express而不是远程SQL Server? - Why can I connect to a local SQL Server Express but not to a remote SQL Server from PHP? 如何使用php连接到SQL Server - How can I connect to SQL Server with php 为什么我不能连接到NNTP服务器? - Why can't I connect to an NNTP server? 为什么我无法连接到我的sql数据库? 我收到错误消息:“无法通过套接字连接到本地MySQL服务器” - Why can't I connect to my sql database? I get the error message: “Can't connect to local MySQL server through socket” 为什么我无法使用 mysqli_connect 和 PHP 7.4 连接到 MySQL 5.3.36 共享服务器,但使用 php 7 可以工作? - Why I can't connect to a MySQL 5.3.36 shared server using mysqli_connect and PHP 7.4, but it will work using php 7.1? 我的电脑有两个 php 文件夹,所以我要么无法连接到 SQL Server,要么无法安装 Laravel - My computer has two php folders so I either can't connect to SQL Server or install Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM