PHP5, ibm_db2 connection problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • michael.schmitz@tietoenator.com

    PHP5, ibm_db2 connection problem

    Hello,

    my tiny PHP5 test application cannot establish a connection to a
    database while I am able to connect to the same database using the DB2
    command line tool.

    Our server is 64 bit system running SuSE Enterprise Linux 10. The PHP
    version installed is v5.1.2.
    su - db2inst1 -c 'db2licm -l'
    Product Name = "DB2 Personal Edition"
    Product Identifier = "DB2PE"
    Version Information = "8.2"
    Expiry Date = "Permanent"
    Annotation = ""
    Other information = ""
    su - db2inst1 -c db2level
    DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
    "SQL08027"
    with level identifier "03080106".
    Informational tokens are "DB2 v8.1.3.128", "s061108", "MI00180", and
    FixPak
    "14".
    Product is installed at "/opt/IBM/db2/V8.1".

    My test application is absolutely simple:
    cat t.php
    <?php
    $database = 'SESYSMLS';
    $user = 'sesys';
    $password = 'sesys';

    $pconn = db2_pconnect($d atabase, $user, $password);

    if ($pconn) {
    echo "Persistent connection succeeded.\n";
    }
    else {
    print db2_conn_errorm sg() . "\n";
    echo "Persistent connection failed.\n";
    }
    ?>

    an produces the following output:
    php5 -f t.php
    [IBM][CLI Driver] SQL1042C An unexpected system error occurred.
    SQLSTATE=58004 SQLCODE=-1042
    Persistent connection failed.

    The variable DB2INSTANCE is set in the shell that I used to execute my
    test application and (although this should not be necessary,
    "ibm_db2.instan ce_name" is set in /etc/php5/cli/php.ini).

    As the following shows, I can connect via the command line client:
    db2 connect to SESYSMLS user sesys using sesys
    Database Connection Information

    Database server = DB2/LINUX 8.2.7
    SQL authorization ID = SESYS
    Local database alias = SESYSMLS

    Restarting the database manager does not change situation.

    Can anybody help?

    I could send the log file produced when creating the ibm_db extension
    and a trace as created by "db2trc" if this helps.

  • frodo2000@gmail.com

    #2
    Re: PHP5, ibm_db2 connection problem

    On 28 Cze, 15:38, "michael.schm.. .@tietoenator.c om"
    <michael.schm.. .@tietoenator.c omwrote:
    Hello,
    >
    my tiny PHP5 test application cannot establish a connection to a
    database while I am able to connect to the same database using the DB2
    command line tool.
    >
    Our server is 64 bit system running SuSE Enterprise Linux 10. The PHP
    version installed is v5.1.2.
    >
    su - db2inst1 -c 'db2licm -l'
    >
    Product Name = "DB2 Personal Edition"
    Product Identifier = "DB2PE"
    Version Information = "8.2"
    Expiry Date = "Permanent"
    Annotation = ""
    Other information = ""
    >
    su - db2inst1 -c db2level
    >
    DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
    "SQL08027"
    with level identifier "03080106".
    Informational tokens are "DB2 v8.1.3.128", "s061108", "MI00180", and
    FixPak
    "14".
    Product is installed at "/opt/IBM/db2/V8.1".
    >
    My test application is absolutely simple:cat t.php
    >
    <?php
    $database = 'SESYSMLS';
    $user = 'sesys';
    $password = 'sesys';
    >
    $pconn = db2_pconnect($d atabase, $user, $password);
    >
    if ($pconn) {
    echo "Persistent connection succeeded.\n";}
    >
    else {
    print db2_conn_errorm sg() . "\n";
    echo "Persistent connection failed.\n";}
    >
    ?>
    >
    an produces the following output:
    >
    php5 -f t.php
    >
    [IBM][CLI Driver] SQL1042C An unexpected system error occurred.
    SQLSTATE=58004 SQLCODE=-1042
    Persistent connection failed.
    >
    The variable DB2INSTANCE is set in the shell that I used to execute my
    test application and (although this should not be necessary,
    "ibm_db2.instan ce_name" is set in /etc/php5/cli/php.ini).
    >
    As the following shows, I can connect via the command line client:
    >
    db2 connect to SESYSMLS user sesys using sesys
    >
    Database Connection Information
    >
    Database server = DB2/LINUX 8.2.7
    SQL authorization ID = SESYS
    Local database alias = SESYSMLS
    >
    Restarting the database manager does not change situation.
    >
    Can anybody help?
    >
    I could send the log file produced when creating the ibm_db extension
    and a trace as created by "db2trc" if this helps.
    Check dbm config for SVCENAME parameter (db2 get dbm config).
    If it is not set:
    - set svcename: db2 update dbm config using svcename service_name
    where service_name is for example db2inst1svce
    - add to /etc/services file: service_name 50000/tcp
    - set DB2COMM variable by: db2set DB2COMM=TCPIP
    - start instance db2start

    If SVCENAME parameter is already set, try to update instance by using:
    db2iupdt instance_name , where instance_name is for example db2inst1

    You can also try another PHP connection syntax:
    $user = "db2admin";
    $password = "***";
    $database = "SAMPLE";
    $hostname = "localhost" ;
    $port = 50000;
    $connect_string = "DRIVER={IB M DB2 ODBC DRIVER};" .
    "DATABASE=$data base;" .
    "HOSTNAME=$host name;" .
    "PORT=$port ;" .
    "PROTOCOL=TCPIP ;" .
    "UID=$user; " .
    "PWD=$password; ";
    $connection = db2_pconnect($c onnect_string,' ','');


    Comment

    • frodo2000@gmail.com

      #3
      Re: PHP5, ibm_db2 connection problem

      Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.

      If it is not:
      - set parameter by using: db2 update dbm cfg using svcename
      db2inst1svce (example for db2inst1)
      - add your service to /etc/services file: db2inst1svce 50000/tcp
      - turn on TCP listener for you instance: db2set DB2COMM=TCPIP
      - start you instance: db2start

      If SVCENAME is set try to update your instance by using: db2iupdt
      db2inst1 (or other instance)

      On the other hand you coukd check another PHP connection syntax:
      $user = "db2admin";
      $password = "***";
      $database = "SAMPLE";
      $hostname = "localhost" ;
      $port = 50000;
      $connect_string = "DRIVER={IB M DB2 ODBC DRIVER};" .
      "DATABASE=$data base;" .
      "HOSTNAME=$host name;" .
      "PORT=$port ;" .
      "PROTOCOL=TCPIP ;" .
      "UID=$user; " .
      "PWD=$password; ";
      $connection = db2_pconnect($c onnect_string,' ','');

      ---
      Best regards,
      Marcin Molak

      Comment

      • michael.schmitz@tietoenator.com

        #4
        Re: PHP5, ibm_db2 connection problem

        Hello Marcin,
        Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.
        SVCENAME is set "db2c_db2in st1" and /etc/services contains the
        following line:

        db2c_db2inst1 50001/tcp # Connection port for DB2 instance
        db2inst1
        If SVCENAME is set try to update your instance by using: db2iupdt
        db2inst1 (or other instance)
        Ok, I tried, but the result is the same.
        On the other hand you coukd check another PHP connection syntax:
        <snip>

        I've tried this as well, but the problem is the same.

        Comment

        • Artur

          #5
          Re: PHP5, ibm_db2 connection problem

          On 28 Cze, 16:49, "michael.schm.. .@tietoenator.c om"
          <michael.schm.. .@tietoenator.c omwrote:
          Hello Marcin,
          >
          Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.
          >
          SVCENAME is set "db2c_db2in st1" and /etc/services contains the
          following line:
          >
          db2c_db2inst1 50001/tcp # Connection port for DB2 instance
          db2inst1
          >
          If SVCENAME is set try to update your instance by using: db2iupdt
          db2inst1 (or other instance)
          >
          Ok, I tried, but the result is the same.
          >
          On the other hand you coukd check another PHP connection syntax:
          >
          <snip>
          >
          I've tried this as well, but the problem is the same.
          FYI:
          Actually DB2 Personal Edition does not allow remote (TCP/IP)
          connection. Only local connections with local protocol are possible.
          Try DB2 Express-C.

          -- Artur



          Comment

          • michael.schmitz@tietoenator.com

            #6
            Re: PHP5, ibm_db2 connection problem

            On 28 Jun., 21:35, Artur <artur.wron...@ gmail.comwrote:
            On 28 Cze, 16:49, "michael.schm.. .@tietoenator.c om"
            >
            >
            >
            <michael.schm.. .@tietoenator.c omwrote:
            Hello Marcin,
            >
            Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.
            >
            SVCENAME is set "db2c_db2in st1" and /etc/services contains the
            following line:
            >
            db2c_db2inst1 50001/tcp # Connection port for DB2 instance
            db2inst1
            >
            If SVCENAME is set try to update your instance by using: db2iupdt
            db2inst1 (or other instance)
            >
            Ok, I tried, but the result is the same.
            >
            On the other hand you coukd check another PHP connection syntax:
            >
            <snip>
            >
            I've tried this as well, but the problem is the same.
            >
            FYI:
            Actually DB2 Personal Edition does not allow remote (TCP/IP)
            connection. Only local connections with local protocol are possible.
            Try DB2 Express-C.
            >
            -- Artur
            Artur,

            I don't think this is true, as I can access the database (for example
            via TotalCommander) from a remote node via ODBC or JDBC (using Aqua
            Data Studio).

            Comment

            • michael.schmitz@tietoenator.com

              #7
              Re: PHP5, ibm_db2 connection problem


              The is one thing I know for sure now: the problem is not one of PHP or
              ibm_db2, but DB2 itself

              Why? The following simple Perl application fails for the same reason:

              #!/usr/bin/perl
              use DBI;
              my $dbh = DBI->connect('dbi:D B2:SSESYSMLS',' sesys','sesys') ;
              my $sth = $dbh->prepare( "SELECT * FROM TEST");
              my $rc = $sth->execute;
              while ($row = $sth->fetchrow_array ref) {
              print"@$row\n";
              }
              $sth->finish;
              $dbh->disconnect;

              Comment

              Working...