Search code examples
phpapachexamppdb2

PHP Warning: PHP Startup: Unable to load dynamic library 'php_ibm_db2.dll'


I want to install the db2 extension for PHP on Windows but it just isn't working. I've tried a lot of different solutions but I still get these:

php.exe

phpinfo()

When I try connection to db2 database

I'm using Apache on XAMPP on port 80. I have installed this: https://github.com/ibmdb/php_ibm_db2/tree/master/PHP%207.4.x/x64/TS and placed it in my C:\xampp\php\ext folder and set "extension=php_ibm_db2.dll" in my php.ini file. (which is in C:\xampp\php)

Only "db2" appearing in phpinfo()

Variable where db2 is appearing

PATH variable


Solution

  • So, I did not manage to connect to my db2 DB with the db2 extension, but here's an alternative I've found -->

    $database = "xxx";
    $hostname = "xxx";
    $user     = "xxx";
    $password = "xxx";
    $port     = 50000;
    
    # Build the connection string
    $driver  = "DRIVER={IBM DB2 ODBC DRIVER};";
    $dsn     = "DATABASE=$database; " .
               "HOSTNAME=$hostname;" .
               "PORT=$port; " .
               "PROTOCOL=TCPIP; " .
               "UID=$user;" .
               "PWD=$password;";
    
    $conn_string = $driver . $dsn;
    
    # Connect
    
    $conn = odbc_connect( $conn_string, "", "" );
    if( $conn )
    {
        echo "Connection succeeded.";
        odbc_close( $conn );
    }
    else
    {
        echo "Connection failed.";
    }
    

    output --> Connection succeeded.

    source --> https://www.ibm.com/docs/en/db2woc?topic=programmatically-php