Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2007
    Posts
    23

    Unanswered: I can't connect to DB through Browser

    I have two servers. One is a linux web server using apache and php. My other server is a windows 2003 server with our phone system and an MSDE database.

    I have a file with the following script:

    <?php
    echo "Does it work?\n";
    mssql_connect("server_ip", "username", "password") or die("Couldn't connect to SQL Server on server_ip");
    echo "IT WORKS!";
    ?>

    Except we're replacing server_ip, username and password with our actual credentials above.

    In the browser I get the output:

    Does it work?
    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: server_ip in /htdocs/public_html/test.php on line 3
    Couldn't connect to SQL Server on server_ip

    From the commande prompt if I take the above script and run it using the php command line interface or turning it into an executable and putting:

    #! /usr/bin/php -q

    on the top line it works fine. My output is:

    Does it work?
    IT WORKS!

    We are also able to connect to it from other servers from both the browser and the command line from various other linux servers in our building. Even those with almost exactly the same setup (same linux distro, same version of apache, same version of php).

    It is my understanding that MSDE (Microsoft Database Engine) is a MSSQL freebie with no admin tools. According to our phone provider the user we're connecting should be wide open that is accessable from anywhere (not restricted by ip address.) We have a third party fire wall that is locking down everything appropriately but I can clearly see where our connection requests to the server are making it through just fine. The windows server firewall is shut down completely.

    On top of all of this from the browser on our server that isn't connecting I can use the php sock functions to open a socket connection to the windows server's ip address on the correct port and it does open the connection.

    Does anyone have any idea what could be causing this one server not to connect via the mssql_connect functions to the windows server's database?

    If you need any further information I'll be glad to provide it! Thanks in advance for any help you can provide!

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    At the point of the call to die(), what is the value of $php_errormsg ? My thought is that if you have other Linux servers that connect to the same SQL Server and the Linux server works fine when the PHP script is executed from the command line but fails when executed from the browser, then I'd want to get diagnostic information from the script that dies in the browser.

    -PatP

  3. #3
    Join Date
    Dec 2007
    Posts
    23
    I changed my script as follows:

    <?php
    ini_set("track_errors","1");
    mssql_connect("server_ip", "username", "password");
    var_dump($php_errormsg);
    ?>

    I get the following output:

    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: server_ip in /htdocs/public_html/test.php on line 4
    string(41) "Unable to connect to server: server_ip"

    So that doesn't really tell me anything new. Are there any other diagnostics you might recommend?

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Try using:
    PHP Code:
    <?php
    ini_set
    ("track_errors","1");
    mssql_connect("server_ip""username""password")
       or die(
    $php_errormsg);
    ?>
    -PatP

  5. #5
    Join Date
    Dec 2007
    Posts
    23
    PHP Code:
    <?php
    ini_set
    ("track_errors","1");
    mssql_connect("server_ip""username""password")
       or die(
    $php_errormsg);
    ?>
    Results in:

    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: server_ip in /htdocs/public_html/test.php on line 3
    Unable to connect to server: server_ip

  6. #6
    Join Date
    Dec 2007
    Posts
    23
    Having scavenged the internet I found a few people recommending to set the environment variable TDSVER = 70.

    So I added:
    putenv("TDSVER=70");

    at the top of my code and it worked once. But every time I've reloaded the page since it doesn't work.

    Why would it work once? What's stopping it from continuing to work? Can I quit technology now and start that illustrious career digging ditches?

  7. #7
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Ok, humor me and try a variant:
    PHP Code:
    <?php 
    ini_set
    ("track_errors","1"); 
    mssql_connect("server_ip""username""password"
       or die(
    "PatP says:  [" $php_errormsg "] plugh!"); 
    ?>
    -PatP

  8. #8
    Join Date
    Dec 2007
    Posts
    23
    It says:

    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: server_ip in /htdocs/public_html/test.php on line 3
    PatP says: [Unable to connect to server: server_ip] plugh!
    My post wasn't long enough so here's another sentence to go at the end so that it will let me post.

  9. #9
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Ok, if there is only one Linux machine that has problems, and that machine only has problems when the PHP runs within a browser, then whatever the problem is, it has to be with the configuration of that specific machine. Because of the last error message you posted, you have to be running a non-standard PHP (that value of $php_errormsg isn't in any standard PHP distribution that I've seen).

    I'm going to move this thread to the PHP forum to see if anyone there can diagnose the problem better than I can, but you might have to take this problem to a PHP specific site to get an answer. I'm sorry that I couldn't solve this one for you, but subtle problems like this are beyond my PHP skills.

    -PatP

  10. #10
    Join Date
    Dec 2007
    Posts
    23
    I eventually just worked around this by a combination of hardcoding some data I needed and migrating other parts of the application to another server.

    Thanks for your help, but I'm moving on with other things now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •