简体   繁体   English

PHP-连接到MSSQL数据库-FreeTDS,PHP 5.3.27,Linux Redhat 64位

[英]PHP - Connecting to MSSQL Database - FreeTDS, PHP 5.3.27, Linux Redhat 64 bit

I'm having a very hard time connecting to a MSSQL database from my Redhad linux box using PHP. 我很难用PHP从Redhad linux框中连接到MSSQL数据库。 I've Googled this thing to death and everything I try doesn't seem to work. 我已经用Google搜索这个东西了,我尝试做的一切似乎都没有用。

I've installed FreeTDS and compiled the PHP install package to create the mssql.so extension. 我已经安装了FreeTDS并编译了PHP安装包以创建mssql.so扩展。 I've placed the extension in the correct extensions directory and I've added the extension to my php.ini file. 我已将该扩展名放置在正确的扩展名目录中,并将该扩展名添加到我的php.ini文件中。

I've also turned off all firewalls to take that out of the picture. 我还关闭了所有防火墙,以消除这种情况。

The latest PHP I tried is: 我尝试的最新PHP是:

<?php

echo "y";
$server = 'SERVERNAME';
echo "e";
// Connect to MSSQL
$link = mssql_connect($server, '<USERNAME>', '<PASSWORD>');
echo "s";
if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}
echo "!";
?>

When I execute this code, I get nothing. 当我执行此代码时,我什么也没得到。 So added those echos and all I get is ye, which tells me that it is not connecting at all. 因此,加上这些回声,我得到的只有是,这告诉我它根本没有连接。 Any help will be greatly appreciated. 任何帮助将不胜感激。 I've tried searching for log files on the server, but I don't really know what to be looking for. 我曾尝试在服务器上搜索日志文件,但我真的不知道要查找什么。

FreeTDS by default uses external configuration to specify services. FreeTDS默认使用外部配置来指定服务。 Check: 校验:

/etc/freetds.conf

or /usr/local/etc/freetds.conf depending on how it was installed. 或/usr/local/etc/freetds.conf,具体取决于安装方式。

"Server" is probably misleading you. “服务器”可能会误导您。 I'm not sure about PHP:mssql_connect()'s ability to take additional parameters, but the freeTDS backend needs more info, in particular: 我不确定PHP:mssql_connect()能否接受其他参数,但是freeTDS后端需要更多信息,尤其是:

  • TDS Version TDS版本
  • Port 港口

These are set up in freetds.conf with a syntax that resembles INI files. 这些是在freetds.conf中用类似于INI文件的语法设置的。 In an example from the sample config file: 在示例配置文件的示例中:

# A typical Microsoft server
[egServer70]
    host = ntmachine.domain.com
    port = 1433
    tds version = 7.0

In my use of freeTDS in any environment, host is misleading, it's the bracketed name freeTDS expects (ie egServer70 in the example above). 在任何环境中使用freeTDS时,主机都是令人误解的,这是freeTDS期望的方括号名称(即,上面示例中的egServer70)。

But trying to test from the higher level abstraction (the PHP:mssql_connect() function) is not enough. 但是尝试从更高级别的抽象(PHP:mssql_connect()函数)进行测试是不够的。 You should really be trying the command line tools that freetds provides, in particular tsql or osql. 您确实应该尝试freetds提供的命令行工具,尤其是tsql或osql。 That's what they are there for. 那就是他们的目的。 Without such testing, it's really hard to know where the failure is. 如果没有这样的测试,这真的很难知道在哪里失败是。

If the connection API supports, you can likely specify all the parameters that freeTDS needs. 如果连接API支持,则可以指定freeTDS所需的所有参数。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM