PHP db_connect problems

Issue #21 resolved
Teemu Halmela created an issue

I seem to have some weird problems when using db2sock libdb400.a and trying to connect to database using PHP db_connect.

This script fails when it is called through a running web server.

<?php

$db = "*LOCAL";
$user = "USER";
$password = "PASSWORD";
$options = array();
$result = db2_connect($db, $user, $password, $options);
var_dump($result);
if($result){
    db2_close($result);
}

Error it gives is this, https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/codes/src/tpc/n950.html

[08-Feb-2018 09:32:16 Europe/Helsinki] PHP Warning:  db2_connect(): Connection failure userid (THA) in /www/zendphp7/htdocs/dbconnect.php on line 7
[08-Feb-2018 09:32:16 Europe/Helsinki] PHP Warning:  db2_connect(): Relaatiotietokantaa *LOCAL ei ole relaatiotietokantahakemistossa. SQLCODE=-950 in /www/zendphp7/htdocs/dbconnect.php on line 7

It works correctly if running straight from the command line

$ /usr/local/zendphp7/bin/php dbconnect.php                      
resource(4) of type (DB2 Connection)

It also works through the web server when I change libdb400.a back to the original.

Are you able to reproduce this problem?

Comments (3)

  1. Teemu Halmela reporter

    I did some investigation and it seems that this function in PaseCliAsync_gen.c is the culprit.

    SQLRETURN SQLConnect( SQLHDBC  hdbc, SQLCHAR * szDSN, SQLSMALLINT  cbDSN, SQLCHAR * szUID, SQLSMALLINT  cbUID, SQLCHAR * szAuthStr, SQLSMALLINT  cbAuthStr )
    {
      SQLRETURN sqlrc = SQL_SUCCESS;
      int myccsid = init_CCSID400(0);
      init_table_lock(hdbc, 0);
      switch(myccsid) {
      case 1208: /* UTF-8 */
      case 1200: /* UTF-16 */
        sqlrc = ILE_SQLConnect( hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr );
        break;
      default:
        sqlrc = libdb400_SQLConnect( hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr );
        break;
      }
      if (init_cli_trace()) {
        dump_SQLConnect(sqlrc,  hdbc, szDSN, cbDSN, szUID, cbUID, szAuthStr, cbAuthStr );
      }
      init_table_unlock(hdbc, 0);
      return sqlrc;
    }
    

    When running through my server it goes to the ILE_SQLConnect route and that doesn't work correctly. If I comment out the switch and only leave libdb400_SQLConnect things start to work again.

    Why does it go to the ILE function when the ccsid comes back as UTF-*?

  2. Former user Account Deleted

    Not SQLConnect per say ...

    This is a problem with SQLOverrideCCSID400. I suspect your fastcgi.conf has SetEnv="CCSID=1208". I have new version works php web fastcgi.conf (Zend Server).

    YIPS Super Driver - 1.1.3-sg6 - test driver - php web fix (Halmela)

    more ...

    PASE libdb400.a will be replaced by db2sock in future. Until replaced a db2sock hack in SQLAllocHandle and SQLAllocEnv should work with php and fastcgi.conf SetEnv="CCSID=1208".

  3. Teemu Halmela reporter

    Yes things seem to work again. And indeed there is CCSID="1208" in our fastcgi config, at least on one machine.

  4. Log in to comment