1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

using mssql_connect to connect to a DB in another server

Discussion in 'PHP' started by priyahdarsini, Apr 27, 2012.

  1. #1
    Hi,


    We are using the below script.

    Actually our DB is in one server (say www.server1.com) and the PHP file

    containing the below connection string is in another server (say

    www.server2.com)

    If we place the PHP file containing the below script in the same server

    where the DB exists that is www.server1.com/dbconnection.php it is working

    fine.

    But if we place the PHP file containing the below script in another server

    www.server2.com/dbconnection.php it is not working. This displays the

    error 'Something went wrong while connecting to MSSQL' Please advise.

    Also to handle error if we use 'die('MSSQL error: ' .

    mssql_get_last_message());' nothing displays just an empty page.

    Please advise how to handle errors.



    Script (dbconnection.php)
    ---------

    <?php
    $server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port

    // Connect to MSSQL
    $link = mssql_connect($server, 'username', 'password');

    if (!$link) {
    die('Something went wrong while connecting to MSSQL');
    }

    // Connect to DB
    $db=mssql_select_db("databasename",$link) or die("Unable to select

    database ");
    ?>

    Thank You
     
    priyahdarsini, Apr 27, 2012 IP
  2. Iann@LFCVPS

    Iann@LFCVPS Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It sounds like your MSSQL server is either firewalled off from all connections or at least from the other server OR MSSQL isn't setup to allow TCP/IP connections. On the server where this doesn't work, can you ping the DB server, or telnet to it on port 1433, or connect to it from something like SQL Server Management Studio?
     
    Iann@LFCVPS, Apr 27, 2012 IP
  3. priyahdarsini

    priyahdarsini Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    We changed the code as below. we only have the access to the FTP of the server where the PHP file containing the connection string exists. We do not have access to the server where the DB is hosted. We only have the details like ip, port, db name, user name and password of the DB

    $server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port

    mssql_min_error_severity(0);
    mssql_min_message_severity(0);

    // Connect to MSSQL
    $link = mssql_connect($server, 'username', 'password');


    if (!$link) {
    die(mssql_get_last_message());
    }

    // Connect to DB
    $db=mssql_select_db("databasename",$link) or die(mssql_get_last_message());

    but below error occurs.

    Warning: mssql_connect() [function.mssql-connect]: Sybase error: Server is unavailable or does not exist. (severity 9) in /home/content/test/Connection.php on line 8

    Please advise for the reason

    Please advise how to display exact error message of mssql_connect function
     
    priyahdarsini, May 2, 2012 IP
  4. 137th Gebirg

    137th Gebirg Active Member

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    I would agree with Iann that it definitely sounds like a firewall issue, blocking port 1433 outside the server's domain. If possible, and if they allow a secure telnet command-line connect (through somthing like PuTTY), try to access the database directly on that server (if it's a unix flavor, that is). If you can connect from inside the command-line environment, then it is definitely being blocked from remote access. If the PHP files were either on the same server as, or in the same domain as, the DB server, you likely wouldn't be experiencing this issue. You will want to contact the system admin of the DB server and ask real nice to put in port forwarding for your access requests. I think that's the right term. NetSec protocols aren't really my thing.
     
    137th Gebirg, May 4, 2012 IP