duanbo1659 2013-10-08 15:56
浏览 52

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

I'm having a very hard time connecting to a MSSQL database from my Redhad linux box using PHP. I've Googled this thing to death and everything I try doesn't seem to work.

I've installed FreeTDS and compiled the PHP install package to create the mssql.so extension. I've placed the extension in the correct extensions directory and I've added the extension to my php.ini file.

I've also turned off all firewalls to take that out of the picture.

The latest PHP I tried is:

<?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.

  • 写回答

1条回答 默认 最新

  • dougongyou7364 2013-12-04 19:07
    关注

    FreeTDS by default uses external configuration to specify services. Check:

    /etc/freetds.conf
    

    or /usr/local/etc/freetds.conf depending on how it was installed.

    "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:

    • TDS Version
    • Port

    These are set up in freetds.conf with a syntax that resembles INI files. 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 (i.e. egServer70 in the example above).

    But trying to test from the higher level abstraction (the PHP:mssql_connect() function) is not enough. You should really be trying the command line tools that freetds provides, in particular tsql or 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100