Previous Next

Thread: mssql_connect()

Last post 04-30-2008 4:32 AM by brashquido. 5 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (6 items)

Sort Posts:

  • 01-03-2007, 11:33 PM

    • nwood888
    • Not Ranked
    • Joined on 01-04-2007, 4:21 AM
    • Posts 4
    • nwood888

    mssql_connect()

    Has anyone had issues using mysql_connect() under this new FastCGI?  I realize this is likely not a bug within FastCGI itself, but was hoping maybe someone had stumbled across a fix.

    The script I'm running is very simple:

    <?php print_r(mssql_connect('host,port','user','pass')); ?>

    Testing from the command line works as expected.  I receive a mssql resource id.  Testing through FastCGI, however, results in a connection failure:

     PHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost,1057 in C:\...\test.php on line 1
     

    I've tested with both 5.1.6 and 5.2.0.

    Thanks,

         Nick

     

  • 02-02-2007, 12:56 PM In reply to

    • rickjames
    • Top 25 Contributor
    • Joined on 10-31-2006, 6:43 PM
    • Posts 193
    • rickjames

    Re: mssql_connect()

    Hi Nick,

    A useful trick when debugging these issues: Try running your script from the command-line, e.g.

    c:\php\php.exe c:\inetpub\wwwroot\test.php

    If you receive the same error, then you know it's got nothing to do with the web server / fastcgi and it really reduces the number of areas to investigate.

    Cheerz,

    Rick.

  • 02-06-2007, 10:47 AM In reply to

    • nwood888
    • Not Ranked
    • Joined on 01-04-2007, 4:21 AM
    • Posts 4
    • nwood888

    Re: mssql_connect()

    Rick, Thanks for the response. I had actually tried from the command line (and noted such in my post).  Unfortunately, it works as expected from the command line, returning a resource id.  It's only through FastCGI that it doesn't work.  I have yet to test it with preview 2, but will do so when time permits.

    Thanks again,

        Nick
     

  • 04-29-2008, 7:46 PM In reply to

    • jpreed00
    • Not Ranked
    • Joined on 04-29-2008, 11:07 PM
    • Posts 8
    • jpreed00

    Re: mssql_connect()

    I am getting this exact same response when using the php_mssql extension.  I've tried the thread safe binaries of php 5.2.5, the non-thread safe binaries as well as trying mssql_pconnect vs. mssql_connect.

    I am absolutely certain that the connection to the database server is open, as I can telnet to the sql server via the proper port.  It *may* be a permissions error, but as I'm using SQL authentication rather than windows authentication, it shouldn't be.
     

    Running the php scripts from the command line result in the proper output, it's only when FastCGI executes that this error is generated.

     Any ideas about what this could be?
     

  • 04-30-2008, 1:40 AM In reply to

    • jpreed00
    • Not Ranked
    • Joined on 04-29-2008, 11:07 PM
    • Posts 8
    • jpreed00

    Re: mssql_connect()

    Alright, I figured out what it was, but now I have to understand why.

    The websites in IIS use a rather restricted user by default for anonymous access, usually just a guest internet account.  Now, I changed this account to an administrator account on my PHP website, and voila, stars align, angels sing and PHP can once again access the database.

    The question is, why, when using sql authentication, am I unable to connect to a database with the generic user, but works perfectly with the administrative user?  Obviously, I wish to restrict permissions as much as possible to limit security vulnerabilities, so having an administrative user attached to the website isn't going to cut it.

    Presumably, there is some magic permission or setting somewhere that needs to be set, or perhaps the base guest users aren't allowed to connect to other machines?  Any Win2k3/IIS gurus out there know?  I'm out of my element, I just recently swapped from Apache/PHP to IIS to guage the performance and installation differences.

    Here is a pre-emptive thanks for all the kind replies.  Thanks!

  • 04-30-2008, 4:32 AM In reply to

    • brashquido
    • Top 25 Contributor
    • Joined on 05-21-2006, 8:31 PM
    • Australia
    • Posts 153
    • IIS MVPs
    • brashquido

    Re: mssql_connect()

    First thing I would do is try configuring PHP in regular CGI mode in IIS. If you get the same errors there it should be a permission based issue with PHP itself, if not it should be an issue with MS FastCGI. Once you have this then you can use something like FileMon to hopefully trace either PHP CGI or FastCGI.

    ----------------
    Dominic Ryan
    Microsoft IIS MVP
    www.iis-aid.com
    My IIS articles
    My PHP articles
    My How-to guides
Page 1 of 1 (6 items)
Page view counter