Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: db2_connect

  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Location
    Atlanta, GA
    Posts
    171
    Thanks
    5
    Thanked 0 Times in 0 Posts

    db2_connect

    I am trying to test my connection to my i5/OS system. Here is my test script. What am I doing wrong? It always says "connection failed"...

    <?php
    //Turn on display_errors
    ini_set('display_errors','1');
    // Display ALL errors including notices
    error_reporting (E_ALL);
    ?>

    <?php
    $user = 'myuser';
    $password = 'mypass';
    $hostname = 'myhost';
    $conn = db2_connect($hostname,$user,$password);
    if ($conn) {
    echo "Connection succeeded.";
    db2_close($conn);
    }
    else {
    echo "Connection failed.";
    echo "<br>$conn";
    }
    ?>
    Last edited by tdavis; 03-25-2009 at 04:55 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Use the db2_conn_errormsg() and analyse the error message.
    PS:Edit your post to remove the connection parameters, if they are real.
    Last edited by abduraooft; 03-25-2009 at 04:55 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    Atlanta, GA
    Posts
    171
    Thanks
    5
    Thanked 0 Times in 0 Posts
    So now I see this message:

    Connection failed.
    Relational database myhost not in relational database directory. SQLCODE=-950

    I have an RDB set up on the i5/OS and it is named "PREPROD".
    I tried using that in an earlier test and it did not work either.

    Here is that code:
    $conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
    "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
    $conn = db2_connect($conn_string, '', '');

    Should I include the DATABASE parameter?
    Last edited by tdavis; 03-25-2009 at 05:05 PM.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I am always reluctant to suggest using a site that competes (at least indirectly) with Coding Forums, but in this case I really think you'd benefit from the expertise available over at dbforums.com.

    (I apologize to CF for doing this, I hope you understand the only reason I did is because DB2 is not something we typically deal with here.)

    I will also post the infomation on a -950 sqlcode error in case it helps you:

    -950 THE LOCATION NAME SPECIFIED IN THE CONNECT STATEMENT IS INVALID OR
    NOT LISTED IN THE COMMUNICATIONS DATABASE

    Explanation: One of the following conditions applies:

    * The location name is blank.

    * The data type of the host variable is not character string.

    * The length attribute of the host variable is greater than 16.

    * The location name does not appear in the LOCATIONS column of the SYSIBM.LOCATIONS table, nor is it the name of the local DB2 subsystem.

    System Action: The statement cannot be executed. The application process is placed in the unconnected state.

    Programmer Response: If the location name is specified as the value of a host variable, ensure that the name is left justified in the host variable and, if necessary, padded on the right with blanks. If this is not the problem, either SYSIBM.LOCATIONS must be updated to include the specified name, or the specified name must be changed to match a name in SYSIBM.LOCATIONS.

    SQLSTATE: 42705

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Location
    Atlanta, GA
    Posts
    171
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for your help!


  •  

    Posting Permissions

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