By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,010 Members | 2,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,010 IT Pros & Developers. It's quick & easy.

PHP5, ibm_db2 connection problem

P: n/a
Hello,

my tiny PHP5 test application cannot establish a connection to a
database while I am able to connect to the same database using the DB2
command line tool.

Our server is 64 bit system running SuSE Enterprise Linux 10. The PHP
version installed is v5.1.2.
su - db2inst1 -c 'db2licm -l'
Product Name = "DB2 Personal Edition"
Product Identifier = "DB2PE"
Version Information = "8.2"
Expiry Date = "Permanent"
Annotation = ""
Other information = ""
su - db2inst1 -c db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
"SQL08027"
with level identifier "03080106".
Informational tokens are "DB2 v8.1.3.128", "s061108", "MI00180", and
FixPak
"14".
Product is installed at "/opt/IBM/db2/V8.1".

My test application is absolutely simple:
cat t.php
<?php
$database = 'SESYSMLS';
$user = 'sesys';
$password = 'sesys';

$pconn = db2_pconnect($database, $user, $password);

if ($pconn) {
echo "Persistent connection succeeded.\n";
}
else {
print db2_conn_errormsg() . "\n";
echo "Persistent connection failed.\n";
}
?>

an produces the following output:
php5 -f t.php
[IBM][CLI Driver] SQL1042C An unexpected system error occurred.
SQLSTATE=58004 SQLCODE=-1042
Persistent connection failed.

The variable DB2INSTANCE is set in the shell that I used to execute my
test application and (although this should not be necessary,
"ibm_db2.instance_name" is set in /etc/php5/cli/php.ini).

As the following shows, I can connect via the command line client:
db2 connect to SESYSMLS user sesys using sesys
Database Connection Information

Database server = DB2/LINUX 8.2.7
SQL authorization ID = SESYS
Local database alias = SESYSMLS

Restarting the database manager does not change situation.

Can anybody help?

I could send the log file produced when creating the ibm_db extension
and a trace as created by "db2trc" if this helps.

Jun 28 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On 28 Cze, 15:38, "michael.schm...@tietoenator.com"
<michael.schm...@tietoenator.comwrote:
Hello,

my tiny PHP5 test application cannot establish a connection to a
database while I am able to connect to the same database using the DB2
command line tool.

Our server is 64 bit system running SuSE Enterprise Linux 10. The PHP
version installed is v5.1.2.
su - db2inst1 -c 'db2licm -l'

Product Name = "DB2 Personal Edition"
Product Identifier = "DB2PE"
Version Information = "8.2"
Expiry Date = "Permanent"
Annotation = ""
Other information = ""
su - db2inst1 -c db2level

DB21085I Instance "db2inst1" uses "32" bits and DB2 code release
"SQL08027"
with level identifier "03080106".
Informational tokens are "DB2 v8.1.3.128", "s061108", "MI00180", and
FixPak
"14".
Product is installed at "/opt/IBM/db2/V8.1".

My test application is absolutely simple:cat t.php

<?php
$database = 'SESYSMLS';
$user = 'sesys';
$password = 'sesys';

$pconn = db2_pconnect($database, $user, $password);

if ($pconn) {
echo "Persistent connection succeeded.\n";}

else {
print db2_conn_errormsg() . "\n";
echo "Persistent connection failed.\n";}

?>

an produces the following output:
php5 -f t.php

[IBM][CLI Driver] SQL1042C An unexpected system error occurred.
SQLSTATE=58004 SQLCODE=-1042
Persistent connection failed.

The variable DB2INSTANCE is set in the shell that I used to execute my
test application and (although this should not be necessary,
"ibm_db2.instance_name" is set in /etc/php5/cli/php.ini).

As the following shows, I can connect via the command line client:
db2 connect to SESYSMLS user sesys using sesys

Database Connection Information

Database server = DB2/LINUX 8.2.7
SQL authorization ID = SESYS
Local database alias = SESYSMLS

Restarting the database manager does not change situation.

Can anybody help?

I could send the log file produced when creating the ibm_db extension
and a trace as created by "db2trc" if this helps.
Check dbm config for SVCENAME parameter (db2 get dbm config).
If it is not set:
- set svcename: db2 update dbm config using svcename service_name
where service_name is for example db2inst1svce
- add to /etc/services file: service_name 50000/tcp
- set DB2COMM variable by: db2set DB2COMM=TCPIP
- start instance db2start

If SVCENAME parameter is already set, try to update instance by using:
db2iupdt instance_name , where instance_name is for example db2inst1

You can also try another PHP connection syntax:
$user = "db2admin";
$password = "***";
$database = "SAMPLE";
$hostname = "localhost";
$port = 50000;
$connect_string = "DRIVER={IBM DB2 ODBC DRIVER};" .
"DATABASE=$database;" .
"HOSTNAME=$hostname;" .
"PORT=$port;" .
"PROTOCOL=TCPIP;" .
"UID=$user;" .
"PWD=$password;";
$connection = db2_pconnect($connect_string,'','');
Jun 28 '07 #2

P: n/a
Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.

If it is not:
- set parameter by using: db2 update dbm cfg using svcename
db2inst1svce (example for db2inst1)
- add your service to /etc/services file: db2inst1svce 50000/tcp
- turn on TCP listener for you instance: db2set DB2COMM=TCPIP
- start you instance: db2start

If SVCENAME is set try to update your instance by using: db2iupdt
db2inst1 (or other instance)

On the other hand you coukd check another PHP connection syntax:
$user = "db2admin";
$password = "***";
$database = "SAMPLE";
$hostname = "localhost";
$port = 50000;
$connect_string = "DRIVER={IBM DB2 ODBC DRIVER};" .
"DATABASE=$database;" .
"HOSTNAME=$hostname;" .
"PORT=$port;" .
"PROTOCOL=TCPIP;" .
"UID=$user;" .
"PWD=$password;";
$connection = db2_pconnect($connect_string,'','');

---
Best regards,
Marcin Molak

Jun 28 '07 #3

P: n/a
Hello Marcin,
Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.
SVCENAME is set "db2c_db2inst1" and /etc/services contains the
following line:

db2c_db2inst1 50001/tcp # Connection port for DB2 instance
db2inst1
If SVCENAME is set try to update your instance by using: db2iupdt
db2inst1 (or other instance)
Ok, I tried, but the result is the same.
On the other hand you coukd check another PHP connection syntax:
<snip>

I've tried this as well, but the problem is the same.

Jun 28 '07 #4

P: n/a
On 28 Cze, 16:49, "michael.schm...@tietoenator.com"
<michael.schm...@tietoenator.comwrote:
Hello Marcin,
Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.

SVCENAME is set "db2c_db2inst1" and /etc/services contains the
following line:

db2c_db2inst1 50001/tcp # Connection port for DB2 instance
db2inst1
If SVCENAME is set try to update your instance by using: db2iupdt
db2inst1 (or other instance)

Ok, I tried, but the result is the same.
On the other hand you coukd check another PHP connection syntax:

<snip>

I've tried this as well, but the problem is the same.
FYI:
Actually DB2 Personal Edition does not allow remote (TCP/IP)
connection. Only local connections with local protocol are possible.
Try DB2 Express-C.

-- Artur

Jun 28 '07 #5

P: n/a
On 28 Jun., 21:35, Artur <artur.wron...@gmail.comwrote:
On 28 Cze, 16:49, "michael.schm...@tietoenator.com"

<michael.schm...@tietoenator.comwrote:
Hello Marcin,
Firstly check if SVCENAME parameter is set, by using: db2 get dbm cfg.
SVCENAME is set "db2c_db2inst1" and /etc/services contains the
following line:
db2c_db2inst1 50001/tcp # Connection port for DB2 instance
db2inst1
If SVCENAME is set try to update your instance by using: db2iupdt
db2inst1 (or other instance)
Ok, I tried, but the result is the same.
On the other hand you coukd check another PHP connection syntax:
<snip>
I've tried this as well, but the problem is the same.

FYI:
Actually DB2 Personal Edition does not allow remote (TCP/IP)
connection. Only local connections with local protocol are possible.
Try DB2 Express-C.

-- Artur
Artur,

I don't think this is true, as I can access the database (for example
via TotalCommander) from a remote node via ODBC or JDBC (using Aqua
Data Studio).

Jun 29 '07 #6

P: n/a

The is one thing I know for sure now: the problem is not one of PHP or
ibm_db2, but DB2 itself

Why? The following simple Perl application fails for the same reason:

#!/usr/bin/perl
use DBI;
my $dbh = DBI->connect('dbi:DB2:SSESYSMLS','sesys','sesys');
my $sth = $dbh->prepare( "SELECT * FROM TEST");
my $rc = $sth->execute;
while ($row = $sth->fetchrow_arrayref) {
print"@$row\n";
}
$sth->finish;
$dbh->disconnect;

Jun 29 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.