DB2 and PHP not working on Apache2 but on CLI - php

I've installed the IBM DB/2 PHP Extension via PECL. Astonishingly, access to my DB/2 server works flawlessly via PHP CLI by using the following code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$connection_string="DATABASE=NAMZPR1;HOSTNAME=172.20.10.162;PORT=50055;PROTOCOL=TCPIP;UID=bouser;PWD=xxx";
$conn = db2_connect($connection_string, "", "");
if ($conn) {
echo "Connection succeeded. \n";
db2_close($conn);
}
else {
echo "Connection failed. " . db2_conn_errormsg() . " \n";
}
?>
when calling the PHP via browser from Apache2 it throws "Connection failed".
I've edited the appropriate PHP.INI file and added the extension as well as added
export LD_LIBRARY_PATH=$HOME/clidriver/odbc_cli/clidriver/lib
to the Apache httpd.conf file.
I am puzzled. It does not work. What part am I missing? Both the PHP CLI and the Apache PHP Module should ouput "Connection succeeded".
The error I get when calling the URL with the PHP is:
Fatal error: Uncaught Error: Call to undefined function db2_connect()
in /var/www/html/db2.php:8 Stack trace: #0 {main} thrown in
/var/www/html/db2.php on line 8
I've managed to load the ibm_db2 module in Apache, here is the output:
ibm_db2 IBM Db2 and compatible databases support enabled Module
release 2.1.7 Binary data mode (ibm_db2.binmode) 1 - DB2_BINARY DB2
instance name (ibm_db2.instance_name) no value Commitment control
(ibm_db2.i5_allow_commit) 0 - DB2_I5_TXN_NO_COMMIT System naming mode
(ibm_db2.i5_sys_naming) 0 - disabled
My message from the Apache Error Log File is
[Thu Feb 09 16:04:33.929426 2023] [php:warn] [pid 629664] [client 172.20.11.18:57220] PHP Warning: db2_connect(): SQLGetDiagRec returned -2 (is the driver working?) in /var/www/html/db2.php on line
8
Edit: I've managed to set the instance name
IBM Db2 and compatible databases support enabled
Module release 2.1.7
Binary data mode (ibm_db2.binmode) 1 - DB2_BINARY
DB2 instance name (ibm_db2.instance_name) db2inst1
Commitment control (ibm_db2.i5_allow_commit) 0 - DB2_I5_TXN_NO_COMMIT
System naming mode (ibm_db2.i5_sys_naming) 0 - disabled
Environment Variables:
export IBM_DB_HOME=/opt/ibm/db2/V11.5
export LD_LIBRARY_PATH=/opt/ibm/db2/V11.5/lib64
export LIBPATH=/home/admini/sqllib/lib
export PATH=/home/admini/sqllib/bin:$PATH
so weired :-(

Related

connecting php to oracle 19c db

Trying to connect to oracle 19c from php the server is not on the same machine as the php, I have so far installed instant client 19_15, added it as a environment variable, and then in the php.ini file I have taken off the semi colon for both the files extension=oci8_19 and extension=pdo_oci not sure what else to do to make the php to connect to the oracle db.
some error messages I have been getting are: PDO: connection failed: could not find driver
and from oci_connect: Fatal error: Uncaught Error: Call to undefined function oci_connect() in Stack trace: #0 {main} thrown in on line 7
p.s. architecture is x64, php version is 8.1.8 and using apache24 lounge

"Warning: oci_connect(): OCIEnvNlsCreate() failed" and "Warning: oci_connect(): Error while trying to retrieve text for error ORA-01804"

I'm new to PHP and Oracle. I'm trying to make a connection between my application in PHP and an Oracle DataBase. I'm using:
Red Hat Enterprise Linux Server release 7.4 (Maipo)
PHP 5.4.16
Apache/2.4.6 (Red Hat Enterprise Linux)
In order to do that I installed Oracle Client and oci8, but I am having these:
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client libraries in /var/www/html/TTS/Portal/Recursos/php/login/Login.php on line 7
Warning: oci_connect(): Error while trying to retrieve text for error ORA-01804 in /var/www/html/TTS/Portal/Recursos/php/login/Login.php on line 7
Line 7 has:
$Conexion=oci_connect('user', 'pass','Ipaddress/DBname');
I read that it could a problem with environment variables
I have in /root/.bash_profile, the following text:
export ORACLE_HOME=/usr/lib/oracle/12.2/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG=American_America.UTF8
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export PATH
In /etc/sysconfig/httpd, I have:
LANG=C
ORACLE_HOME=/usr/lib/oracle/12.2/client64
LD_LIBRARY_PATH=$ORACLE_HOME/lib
NLS_LANG=American_America.UTF8
export ORACLE_HOME
export LD_LIBRARY_PATH
export NLS_LANG
phpinfo() shows me the following:
Apache environment and Environment
PHP variables and Oci8
I don't know how to fix the problems, I'd appreciate any help
Thanks

How to setup a mongodb with php XAMPP?

I am a beginner to mongoDB, I want to learn mongoDB. So I read few tutorials and tried to configure mongoDB in my local machine, for that I have downloaded mondoDB's php_mongo.dll file and placed that on my local machine into the path "php/ext/php_mongo.dll" and after that I added this code "extension = php_mongo.dll" to php.ini file, after that I am trying run my XAMPP server but immediately it is showing the below error :
C:xampp\php\ext\php_mongo.dll is either not designed to run on Windows
or it contains an error. Try installing the program again using the
original installation media or contact your system administrator or
the software vendor for support.
after that somehow Apache server has been started And when I try to run the application on browser by URL http://localhost/mongoapp/index.php then it is throwing the following error:
Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\xampp\htdocs\mongoapp\index.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\mongoapp\index.php on line 3
File: index.php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->mydb;
echo "Database mydb selected";
My php version is "PHP Version 7.0.8". hope someone helps, Thanks in advance.
Check your phpinfo if mongodb is loaded.
Download mongodb from "https://www.mongodb.com/download-center?jmp=nav#community" and install.
Check your architecture in phpinfo match with mongodb.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

Bluemix PHP app fails on LDAP connection

This is a follow up ticket to one which was closed without answer:
https://stackoverflow.com/questions/34515574/ibm-bluemix-authentication-using-tivoli-ldap
I have migrated a PHP app which requires LDAP authentication to Bluemix and I am getting the following error:
2016-01-08T10:28:53.87+0000 [App/0] OUT 10:28:53 httpd | [Fri Jan 08 10:28:53.869250 2016] [proxy_fcgi:error] [pid 44:tid 139703240013568] [client 169.53.20.45:7120] AH01071: Got error 'PHP message: PHP Fatal error: Call to undefined function ldap_connect() in /home/vcap/app/htdocs/utils/LoginLDAP.Class.php on line 21\n', referer: http://sbrooms.w3ibm.mybluemix.net/index.php
Please note that this is not the public Bluemix, but the internal IBM one (w3ibm.mybluemix.net), hence the connection to the LDAP server should be available.
Do I have to explicitly request the connection to the LDAP server, or something else is going wrong?
Thanks,
Pimmy
Looks like the LDAP-Extension for PHP is not installed on the WebServer. The PHP message: PHP Fatal error: Call to undefined function ldap_connect() suggests that.
You can check that by adding a page to your webserver with the following content:
<?php
phpinfo();
Call that website in a webbroser and check whether there is any trace of the LDAP-extension. If not, you will need to get that extension. As there are many different ways to install it (from recompiling PHP to a call to your systems package-manager) I need more information on how your system - and especially PHP - has been installed.
Hope that helps!

Mongodb with php on Windows 7 (32 bit) with apache not working

I am trying to run mongodb code with the following system configuration:
Operating System: Windows 7 (32 bit)
PHP Version: 5.2.9 Apache
Version: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i
PHP/5.2.9
I am using XAMPP in my system.
What I did to configure mongodb with the xampp is below:
I went to https://github.com/mongodb/mongo-php-driver/downloads and download the first link (php_mongo-1.3.2RC1.zip) zip.
After unzipping the file I copied php_mongo-1.3.2RC1-5.2-vc9.dll DLL file in xampp/php/ext/ directory in my xampp installed directory
Then add extension=php_mongo-1.3.2RC1-5.2-vc9.dll in the php.ini file
Restarted xampp server
Then I saw the xampp phpinfo() and it is displaying that mongodb is installed. Please follow the image below from my phpinfo() page
Now I wrote a sample code for using mongodb as below:
<?php
$m = new Mongo();
$db = $m->learningmongo;
$people = $db->people;
?>
and it is displaying the Fetal error on screen as below:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: Unknown error' in E:\xampp\htdocs\mongo\index.php:3 Stack trace: #0 E:\xampp\htdocs\mongo\index.php(3): Mongo->__construct() #1 {main} thrown in E:\xampp\htdocs\mongo\index.php on line 3
Where I am doing wrong, please guide me. Any code sample and web link would be highly appreciated.

Categories