PHP MSSQL connection problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mj@lightfootarts.com

    PHP MSSQL connection problem.

    Hello, thanks for the help.

    I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm
    firewall)

    Apache 2.0.52
    MySQL 4.1.7
    PHP 5.1.0-dev

    I have developed a PHP/MySQL web app that tracks jobs for me, and we
    use it on our peer-to-peer network. This program works GREAT :)

    I also have a company website hosted remotely, where clients can place
    a job request.

    Win2k
    IIS
    MS SQL Sever 2000

    On this web site we have a MSSQL database that records all the jobs
    that where placed through the web site.

    What I what to do know is connect to the remote MSSQL server and run
    some SELECT statements with PHP.

    NOW ... I can connect to the remote MS SQL sever with the client tools,
    Enterprise Manager, and I can setup and connect with ODBC.

    What I can't do is get php to connect to it.

    - I have ntwdblib.dll in my c:\windows\syst em32 & c:\apache2\bin &
    c:\php folders (year 2000 version)

    - In SQL Sever Client Network Utility I only have TCP/IP as an "Enabled
    protocols"

    - I have extension=php_m ssql.dll in my php.ini

    - when I run:

    function_exists ('mssql_connect ');

    it returns true so I know that php_mssql.dll loaded OK

    This is the code I try and connect with:

    <?php

    $host="mssql.du mbname.net";
    $user="user";
    $password="pass word";

    mssql_connect($ host,$user,$pas sword) or die ("could not connect to
    server"); // <-------- It always dies here. :(

    mssql_select_db ("trtrades") or die ("could not connect to DB");

    ....


    ?>

    I know that the $host, $user, and $password are right because I can
    connect to the remote DB with the client tools.


    I also tried connect using php's ODBC functions:( I have already
    created the DNS that is need)

    odbc_connect($h ost,$user,$pass word) or die("can not connect to sever");
    // <--------- This always dies as well

    and still know luck ...


    I have been working at this for a few days now, and searched all over
    the net and groups for a solution to my problem with no luck.

    I hope that someone might be able to help.

    Cheers;

    VanMan

  • Jerry Stuckle

    #2
    Re: PHP MSSQL connection problem.

    mj@lightfootart s.com wrote:[color=blue]
    > Hello, thanks for the help.
    >
    > I am running a WinXP Pro w/ SP2 (my home computer, with ZoneAlarm
    > firewall)
    >
    > Apache 2.0.52
    > MySQL 4.1.7
    > PHP 5.1.0-dev
    >
    > I have developed a PHP/MySQL web app that tracks jobs for me, and we
    > use it on our peer-to-peer network. This program works GREAT :)
    >
    > I also have a company website hosted remotely, where clients can place
    > a job request.
    >
    > Win2k
    > IIS
    > MS SQL Sever 2000
    >
    > On this web site we have a MSSQL database that records all the jobs
    > that where placed through the web site.
    >
    > What I what to do know is connect to the remote MSSQL server and run
    > some SELECT statements with PHP.
    >
    > NOW ... I can connect to the remote MS SQL sever with the client tools,
    > Enterprise Manager, and I can setup and connect with ODBC.
    >
    > What I can't do is get php to connect to it.
    >
    > - I have ntwdblib.dll in my c:\windows\syst em32 & c:\apache2\bin &
    > c:\php folders (year 2000 version)
    >
    > - In SQL Sever Client Network Utility I only have TCP/IP as an "Enabled
    > protocols"
    >
    > - I have extension=php_m ssql.dll in my php.ini
    >
    > - when I run:
    >
    > function_exists ('mssql_connect ');
    >
    > it returns true so I know that php_mssql.dll loaded OK
    >
    > This is the code I try and connect with:
    >
    > <?php
    >
    > $host="mssql.du mbname.net";
    > $user="user";
    > $password="pass word";
    >
    > mssql_connect($ host,$user,$pas sword) or die ("could not connect to
    > server"); // <-------- It always dies here. :(
    >
    > mssql_select_db ("trtrades") or die ("could not connect to DB");
    >
    > ...
    >
    >
    > ?>
    >
    > I know that the $host, $user, and $password are right because I can
    > connect to the remote DB with the client tools.
    >
    >
    > I also tried connect using php's ODBC functions:( I have already
    > created the DNS that is need)
    >
    > odbc_connect($h ost,$user,$pass word) or die("can not connect to sever");
    > // <--------- This always dies as well
    >
    > and still know luck ...
    >
    >
    > I have been working at this for a few days now, and searched all over
    > the net and groups for a solution to my problem with no luck.
    >
    > I hope that someone might be able to help.
    >
    > Cheers;
    >
    > VanMan
    >[/color]

    What kind of error message do you get from your connect attempts (other
    than the die messages)? Did you check the user notes in the
    documentation (http://www.php.net/manual/en/functio...-connect.php)?


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • mj@lightfootarts.com

      #3
      Re: PHP MSSQL connection problem.

      Thanks for the reply Jerry. Yes I have readed ALL the user notes, and
      every group I can find on this issue. I believe that other people have
      had the same problem, and I followed the steps they tool to fix it ...
      but still no luck :(

      I don't get any kind of error message. For example when I run this
      code:

      <?php

      ....

      $connt = mssql_connect($ host,$user,$pas sword);

      if(!$connt)
      {
      $msg = mssql_get_last_ message();
      echo $msg;
      }

      ....
      ?>

      $msg if NULL.

      Is there any way to tell if my mssql_connect() function is actual going
      out to the remote sever and trying to connect? OR if the function is
      failing on the local end?

      also, these are my MSSQL setting in my php.ini file

      mssql.allow_per sistent = On
      mssql.max_persi stent = -1
      mssql.max_links = -1
      mssql.min_error _severity = 10
      mssql.min_messa ge_severity = 10
      mssql.compatabi lity_mode = On
      ;mssql.connect_ timeout = 5
      ;mssql.timeout = 60
      ;mssql.textlimi t = 4096
      ;mssql.textsize = 4096
      ;mssql.batchsiz e = 0
      ;mssql.datetime convert = On
      mssql.secure_co nnection = On
      mssql.max_procs = 25

      Now, I don't know, but could there be something I need to setup in my
      Apache 2's httpd.conf ?

      Also I have ZoneAlarm allowing TCP on port 80, and 1433.

      I would LOVE any help on this anyone can give me, even if it is only a
      GOOD guess. I'm willing to try anything at this point.

      Cheers;

      VanMAn

      Comment

      • Jerry Stuckle

        #4
        Re: PHP MSSQL connection problem.

        mj@lightfootart s.com wrote:[color=blue]
        > Thanks for the reply Jerry. Yes I have readed ALL the user notes, and
        > every group I can find on this issue. I believe that other people have
        > had the same problem, and I followed the steps they tool to fix it ...
        > but still no luck :(
        >
        > I don't get any kind of error message. For example when I run this
        > code:
        >
        > <?php
        >
        > ...
        >
        > $connt = mssql_connect($ host,$user,$pas sword);
        >
        > if(!$connt)
        > {
        > $msg = mssql_get_last_ message();
        > echo $msg;
        > }
        >
        > ...
        > ?>
        >
        > $msg if NULL.
        >
        > Is there any way to tell if my mssql_connect() function is actual going
        > out to the remote sever and trying to connect? OR if the function is
        > failing on the local end?
        >
        > also, these are my MSSQL setting in my php.ini file
        >
        > mssql.allow_per sistent = On
        > mssql.max_persi stent = -1
        > mssql.max_links = -1
        > mssql.min_error _severity = 10
        > mssql.min_messa ge_severity = 10
        > mssql.compatabi lity_mode = On
        > ;mssql.connect_ timeout = 5
        > ;mssql.timeout = 60
        > ;mssql.textlimi t = 4096
        > ;mssql.textsize = 4096
        > ;mssql.batchsiz e = 0
        > ;mssql.datetime convert = On
        > mssql.secure_co nnection = On
        > mssql.max_procs = 25
        >
        > Now, I don't know, but could there be something I need to setup in my
        > Apache 2's httpd.conf ?
        >
        > Also I have ZoneAlarm allowing TCP on port 80, and 1433.
        >
        > I would LOVE any help on this anyone can give me, even if it is only a
        > GOOD guess. I'm willing to try anything at this point.
        >
        > Cheers;
        >
        > VanMAn
        >[/color]

        VanMAn,

        What about your php.log? And what's your error reporting? For
        debugging like this you should have error_reporting =E_ALL.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • mj@lightfootarts.com

          #5
          Re: PHP MSSQL connection problem.

          Thanks again Jerry for the reply.

          I have my error reporting set to:
          error_reporting = E_ALL & ~E_NOTICE




          [05-Jun-2005 02:00:11] PHP Warning: mssql_connect() [<a
          href='function. mssql-connect'>functi on.mssql-connect</a>]: Unable to
          connect to server: mssql.dumbname. net in
          C:\WebServ\wwwr oot\htdocs\mssq l_send.php on line 12

          [05-Jun-2005 02:00:21] PHP Warning: mssql_connect() [<a
          href='function. mssql-connect'>functi on.mssql-connect</a>]: Unable to
          connect to server: mssql.dumbname. net in
          C:\WebServ\wwwr oot\htdocs\mssq l_send.php on line 12

          [05-Jun-2005 02:03:42] PHP Warning: mssql_connect() [<a
          href='function. mssql-connect'>functi on.mssql-connect</a>]: Unable to
          connect to server: mssql.dumbname. net in
          C:\WebServ\wwwr oot\htdocs\mssq l_send.php on line 12

          So this what is reported in my php Error.log

          Jerry do you know of any way that I can test to see if the
          mssql_connect() is making it to the remote server, without have full
          access to the remote server? I just what to make sure that the request
          is getting there so I can narrow down where my problem is. On my side
          or the remote mssql servers side. ( I think my side)

          Also if you have any ideas on how I could get around this problem, if I
          can't solve it would also be of get value to me. even if I have to
          write a CGI script in another language.

          Thanks for the help :)

          Cheers;

          Comment

          • mj@lightfootarts.com

            #6
            Re: PHP MSSQL connection problem.

            OMG .... ok I think I got it going ... ALMOST :)

            I found this:

            PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


            and the comment by:
            Ilmars Poikans in the top 1/4 of the page.

            He said that he had to change his Registry to get it to work

            <quote>
            I'm working on Windows XP with PHP5 (should work with PHP4 also because
            ntwdblib.dll is the same).

            My problem was that I needed to connect to remote MS SQL server over
            TCP/IP (named pipes weren't an option), but I couldn't, because named
            pipes were used all the time.

            One of the possible solutions is to install SQL Client Tools and
            configure TCP/IP support. I hadn't SQL Server installation disk, so I
            found fast solution with registry editing.

            I added to registry following entry:

            [HKEY_LOCAL_MACH INE\SOFTWARE\Mi crosoft\ MSSQLServer\Cli ent\ConnectTo]
            (strip space)
            "DSQUERY"="DBNE TLIB"

            It worked! Just specify servername in form "host" or "host,port" . I
            successfully connected to remote MSSQL7 and MSSQL2000.
            </quote>

            So I added that value pair, and the next time I can my php code I got
            this message:

            Login failed for user 'NT AUTHORITY\ANONY MOUS LOGON'.
            could not connect to DB

            So I think it is working. Now how do I tell it to use SQL Server
            Authentication, not Windows Authentication ?

            Once I get that working I'm cooking with gas :)

            Thanks for the help

            Cheers;

            VanMan

            Comment

            • mj@lightfootarts.com

              #7
              Re: PHP MSSQL connection problem.

              OMG :)

              I got it working, right on !!!

              So ... for anyone easy that is have the same problem, I made the follow
              registry entry on my local server:

              HKEY_LOCAL_MACH INE\SOFTWARE\M­ icrosoft\ MSSQLServer\Cli ent\ConnectTo]
              DSQUERY=DBNETLI B

              and then in my php.ini in the MSSQL area I set:

              mssql.secure_co nnection = Off

              AND IT WORK .... YES!!!

              Thanks for the Help Jerry.

              Cheers;

              VanMan

              Comment

              • Jerry Stuckle

                #8
                Re: PHP MSSQL connection problem.

                mj@lightfootart s.com wrote:[color=blue]
                > OMG :)
                >
                > I got it working, right on !!!
                >
                > So ... for anyone easy that is have the same problem, I made the follow
                > registry entry on my local server:
                >
                > HKEY_LOCAL_MACH INE\SOFTWARE\M­ icrosoft\ MSSQLServer\Cli ent\ConnectTo]
                > DSQUERY=DBNETLI B
                >
                > and then in my php.ini in the MSSQL area I set:
                >
                > mssql.secure_co nnection = Off
                >
                > AND IT WORK .... YES!!!
                >
                > Thanks for the Help Jerry.
                >
                > Cheers;
                >
                > VanMan
                >[/color]

                VanMan,

                Glad you got it working. But I didn't help much. Just asked a few
                questions - you did all the work! :-).



                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                Working...