简体   繁体   中英

Connecting php server to DB2 from outside IBM Cloud

I am following the process as described here: https://www.ibm.com/support/knowledgecenter/en/SSHRBY/com.ibm.swg.im.dashdb.doc/connecting/connect_connecting_php.html

I have completed the instalation and I have even run the validation command in shell

db2cli validate -dsn DashDB -connect -user bluadmin -passwd 'your_secret_password'

see output below

But still my www page crashes on the line

$conn = odbc_connect( $conn_string, "", "" );

becasue it does not recognize the odbc_connect function.

Any feedback and hopefully help is very welcome.

在此处输入图片说明

Your question is not about programming, but instead it is about configuration.

It is best if you detail your php version and your linux distro details fully every time you ask for help.

You already successfully configured db2dsdriver.cfg and successfully validated a CLI connection to the remote Db2 database. That is essential.

The next step is to ensure that both ODBC and PHP are configured appropriately.

It may help to verify all the following items:

  • Verify php-odbc is installed to match your version of php . Use the package-manager (eg yum or apt etc.) for your linux distro to install it, there's plenty of pages to help you with that.

  • Verify the php.ini has enabled: extension=odbc.so ( for Linux it seems this is not default with php7).

  • Verify that the command-line php -m shows that odbc is loaded

  • If you configured a unixODBC DSN then verify you can successfully connect to the DSN with isql command on linux (to verify that your odbc.ini and odbcinst.ini are properly configured with the Db2 driver and the DSN details). Use odbcinst -j to show the path to odbc.ini and odbcinst.ini for your distro. There's plenty of pages to show how to configure those files, and how to run the isql command line. Usage of a DSN is optional, but it can help with sanity checking and centralises the connection strings instead of having them replicated in php scripts.

  • verify the ibm_db2 driver is loaded and pdo_ibm (if using PDO interfaces) with the php -m command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM