Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2015-05-10T23:16:32Z by GregMc
mortenb
mortenb
49 Posts
ACCEPTED ANSWER

Pinned topic php ibm_db2.so module not working.

‏2008-05-06T12:27:54Z |
Hi
I get the old odbc driver to work, but not the db2_* driver, I've googled around for this but there is
no solution. This works find on most machines, but not on this linux-ia32 db2v9.1 opensuse10.2.

php is compiled with:
. /home/db2inst1/sqllib/db2profile
./configure --with-ibm-db2=/home/db2inst1/sqllib --with-apxs2=/opt/apache/bin/apxs

<?php phpinfo(); ?>

does not reveal anything regarding ibm_db2.so driver

if I look at the shell php I see the db2 dso's are linked in:
% ldd /usr/local/bin/php | grep db2
libdb2.so.1 => /home/db2inst1/sqllib/lib/libdb2.so.1 (0xb6601000)
libdb2install.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2install.so.1 (0xb6377000)
libdb2g11n.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2g11n.so.1 (0xb5d63000)
libdb2locale.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2locale.so.1 (0xb5d4e000)
libdb2osse.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2osse.so.1 (0xb5acb000)
libdb2genreg.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2genreg.so.1 (0xb5a8b000)
libdb2trcapi.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2trcapi.so.1 (0xb5a81000)
libdb2dascmn.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2dascmn.so.1 (0xb5a60000)
libimf.so => /opt/ibm/db2/V9.1/lib32/libimf.so (0xb5882000)
libdb2osse_db2.so.1 => /opt/ibm/db2/V9.1/lib32/libdb2osse_db2.so.1 (0xb57b7000)

Modules does not show up:
% php -m | grep -i db2
%

It does not work:
% . ~db2inst1/sqllib/db2profile
% php db2test1.php

Fatal error: Call to undefined function db2_connect() in /dist/secana-dev/SCP-2-2-TAG-branch/s3/secana.com/php/db2test1.php on line 6

% cat db2test1.php
<?php
$database = 'db2test';
$user = 'db2inst1';
$password = 'db2pw';
$connection = db2_connect($database, $user, $password);
if ($connection) {
echo "Connection succeeded."."\n";
}
else {
echo "Connection failed."."\n";
echo db2_conn_errormsg ($connection);
}
db2_close($connection);
?>

Thanks any help appreciated.
using odbc driver is not an option.

--
Morten Bjoernsvik - Experian Decision Analytics AS - Norway
Updated on 2008-05-07T21:57:05Z at 2008-05-07T21:57:05Z by mortenb
  • mortenb
    mortenb
    49 Posts
    ACCEPTED ANSWER

    Re: php ibm_db2.so module not working.

    ‏2008-05-06T15:14:15Z  in response to mortenb
    Hi

    I found the problem

    php.ini extension should not hold a path

    php -c /etc db2test1.php
    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613//usr/local/lib/php/extensions/no-debug-non-zts-20060613/ibm_db2.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613//usr/local/lib/php/extensions/no-debug-non-zts-20060613/ibm_db2.so: cannot open shared object file: No such file or directory in Unknown on line 0

    So changing it back worked. this error does not show up unless you use the '-c path' option

    % php -c /etc db2test1.php
    Connection succeeded.

    % cat /etc/php.ini
    extension=ibm_db2.so
    ibm_db2.instance_name db2inst2

    --
    Morten Bjoernsvik, Experian Decision Analytics AS - Norway
    • mortenb
      mortenb
      49 Posts
      ACCEPTED ANSWER

      Re: php ibm_db2.so module not working.

      ‏2008-05-07T06:50:02Z  in response to mortenb
      Now things works perfectly.

      When compiling php it does not honour --sysconfdir=/etc
      as a place to find /etc/php.ini

      In this file you need to explicitly add the extension=db2_so.so
      for web you must have the PHPIniDir="/etc/php.ini"

      You see it when loading the modules
      % php -m | grep db2
      <nothing, this will not work>
      % php -c /etc -m | grep db2
      ibm_db2

      The IBM PHP DB2 howto on developerworks is outdated:
      http://www.ibm.com/developerworks/db2/library/techarticle/dm-0502scott/
      (I'll send an email)

      --
      Morten Bjoernsvik, Experian Decision Analytics AS, Norway
      • krook
        krook
        3 Posts
        ACCEPTED ANSWER

        Re: php ibm_db2.so module not working.

        ‏2008-05-07T13:16:02Z  in response to mortenb
        Hi Morten,

        That dW article refers to the Unified ODBC extension, not the newer ibm_db2 one that you're using. The author whose email address is shown is also no longer at IBM.

        Updated information for building PHP with the ibm_db2 extension with Apache/IBM HTTP Server is available in chapter 4 of Developing PHP Applications for IBM Data Servers in section 4.1.4: "Apache and PHP installation and configuration."

        Are you building with a Web server? Either way those steps will provide you with the PHP command line tool you need.
        Daniel Krook
        • mortenb
          mortenb
          49 Posts
          ACCEPTED ANSWER

          Re: php ibm_db2.so module not working.

          ‏2008-05-07T21:57:05Z  in response to krook
          Thanks Daniel

          That reedbook is great. All my questions seem to be answered there :-)

          --
          Morten Bjoernsvik, Experian Decision Analytics AS, Norway
      • GregMc
        GregMc
        1 Post
        ACCEPTED ANSWER

        Re: php ibm_db2.so module not working.

        ‏2015-05-10T23:16:32Z  in response to mortenb

        I spent almost my full 2-day weekend trying to resolve this same issue and finally cam across this post today which helped.  I'm running PHP 5.4.16 on Centos 7 with Apache 2.4.6 trying to connect PHP to BigInsights BigSQL which uses the DB2 driver.  I had been able to install and build the ibm_db2.so, catalog the remote BIGSQL db and have it and the  db2inst recognized along with sourcing the db2profile; but my web pages still were getting the "Call to undefined function db2_connect()" errors.

        This post was the key as I was experiencing the same issues you listed here.  I did need to modify my httpd.conf file to include the PHPINIDir "/etc/php.ini".  So thanks for taking the time to post this.  You never know when it may actually continue to help someone years later.  The IBM Redbook does not include a few minor but key steps to get the PHP web sconnection to DB2 work.  I literally had to pull from multiple google search results to piece the necessary steps together.  I had so much trouble trying to actually determine if the ibm_db2 module information should appear in the PHP info page and now that it is working I see that it should appear there.