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 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)