Hanany
Hanany

Reputation: 53

Fatal error: Call to undefined function db2_connect() using WAMP when trying to connect to Derby DB

I hope someone can help me with this error. I know it pops up due to php not recognizing the php_ibm_db2.dll module, but I've tried everything and nothing works. I've looked for tutorials, but many of them are very old and refers to the old version of IBM products which makes it harder for me to understand.

Older similar questions posted here either goes unanswered or solved vaguely.

Here are the basics:

I needed to connect to the db using php and retrieve the data. I tried using odbc but I received 'Function Unsupported' with both IBM DB2 ODBC Driver and IBM Data Server Driver for ODBC, so I scrapped the idea and decided to go with db2 functions instead.

Here's what I've tried:

*I previously configured PHP to include Firebird headers, so I know I modified the correct .conf & .ini. The PHP folder is also defined in the environment variables.

PHP error log contains the following:

PHP Warning:  PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ibm_db2.dll' - %1 is not a valid Win32 application.

The code:

$username = "username";
$password = "password";
$hostname = "localhost";
$port = "1527";
$database="C:\Users\me\Desktop\dbname"; //not real definition

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;"."HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$username;PWD=$password";

$connection = db2_connect($conn_string, '', '');
if ($connection) {
   echo "Connection succeeded."."\n";
}
else {
   echo "Connection failed."."\n";
   echo db2_conn_errormsg ($connection);
}

Thank you in advance

Upvotes: 0

Views: 4552

Answers (1)

Hanany
Hanany

Reputation: 53

Thanks to @RiggsFolly and a question I failed to find again to link here, I figured it out now.

For anyone trying to enable db2 functions in Windows x64 and thinks php.net installing guide is not very specific, here are the steps (or at least, what I used to solve it):

  1. Install a 32-bit WAMPServer

  2. Install IBM Express-C x32. This comes with the IBM DB2 ODBC Driver.

  3. Download php_ibm_db2.dll according to your PHP version. Copy into PHP extension folder and enable it in the PHP.ini

  4. To configure the DSN for the x32 ODBC Driver, use the x32 ODBC Data Source Administrator in C:\Windows\SysWOW64\odbcad32.exe.

  5. Restart WAMPServer and check PHPInfo(). ibm db2 should have it's own section now

I hope this will be useful to someone.

OR

just download a suitable version from PECL. I just discovered that and I feel super dumb.

Upvotes: 1

Related Questions