问题
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.
回答1:
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 (e.g. 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 loadedIf you configured a unixODBC DSN then verify you can successfully connect to the DSN with
isql
command on linux (to verify that yourodbc.ini
andodbcinst.ini
are properly configured with the Db2 driver and the DSN details). Useodbcinst -j
to show the path toodbc.ini
andodbcinst.ini
for your distro. There's plenty of pages to show how to configure those files, and how to run theisql
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.
来源:https://stackoverflow.com/questions/57891018/connecting-php-server-to-db2-from-outside-ibm-cloud