Php+mssql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sheckel
    New Member
    • Mar 2007
    • 2

    Php+mssql

    I am running PHP on one server (IIS), trying to connect to SQL Server on another server (all in-house, none available off campus). SQL Server Client has been loaded onto the box running PHP. My script stops at the mssql_connectio n() function, apparently not connecting to the other server. I've started working with the folks over at php.net, but I would appreciate any help I can get from anyone.
  • Bhavesh1978
    New Member
    • Mar 2007
    • 32

    #2
    Originally posted by sheckel
    I am running PHP on one server (IIS), trying to connect to SQL Server on another server (all in-house, none available off campus). SQL Server Client has been loaded onto the box running PHP. My script stops at the mssql_connectio n() function, apparently not connecting to the other server. I've started working with the folks over at php.net, but I would appreciate any help I can get from anyone.
    why not try download wamp server which is all in one.. you get, php, mysql, apache all in one server
    www.wampserver. com

    TRY IT

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Originally posted by sheckel
      I am running PHP on one server (IIS), trying to connect to SQL Server on another server (all in-house, none available off campus). SQL Server Client has been loaded onto the box running PHP. My script stops at the mssql_connectio n() function, apparently not connecting to the other server. I've started working with the folks over at php.net, but I would appreciate any help I can get from anyone.
      what is the error.? where is the coding.?
      to help over i need to know about the connection string that you used to connect to mssql .post it here.

      Comment

      • sheckel
        New Member
        • Mar 2007
        • 2

        #4
        PHP + MS SQL Server – SUCCESS!

        Thanks to all!

        PHP is on an IIS server, SQL Server is on a different server in the same domain.

        Changes made to PHP
        o Add MS SQL Server Client Tools
        o Uncomment the extension=php_m ssql.dll statement in the php.ini file
        o Add system variable PHPRC value c:\php
        o Use ntwdblib.dll version 2000.80.194.0 (ver 2000.2.8.0 did not work); copied the files to c:\windows\syst em32 directory on the PHP server

        Changes made to IIS
        o Set up IUSER_machinena me account with password

        Changes made to MS SQL Server
        o Create IUSER_machinena me account with password – synchronize with IIS password
        o Add IUSER as login
        o Add IUSER as user on database, including permissions

        After all of these steps were followed, the following PHP script ran correctly:

        <html><head><ti tle>MsSQL Table Viewer</title></head><body>
        <?php
        $db_host = hostname';
        $db_user = 'username';
        $db_pwd = 'password';
        $database = 'dbname';
        $table = 'tablename';

        if (!mssql_connect ($db_host, $db_user, $db_pwd))
        die("Can't connect to database");
        if (!mssql_select_ db($database))
        die("Can't select database");

        // sending query
        $result = mssql_query("SE LECT * FROM {$table}");
        if (!$result) {
        die("Query to show fields from table failed");
        }

        $fields_num = mssql_num_field s($result);
        echo "<h1>Table: {$table}</h1>";
        echo "<table border='1'><tr> ";
        // printing table headersfor($i=0 ; $i<$fields_num; $i++)
        {

        $field = mssql_fetch_fie ld($result);
        echo "<td>{$fiel d->name}</td>";
        }
        echo "</tr>\n";
        // printing table rows

        while($row = mssql_fetch_row ($result))
        {
        echo "<tr>";

        // $row is array... foreach( .. ) puts every element
        // of $row to $cell variable

        foreach($row as $cell)
        echo "<td>$cell</td>";
        echo "</tr>\n";
        }
        mssql_free_resu lt($result);
        ?>

        </body></html>

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Nice work!

          Comment

          Working...