Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / June 2007

Tip: Looking for answers? Try searching our database.

PHP5, ibm_db2 connection problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
michael.schmitz@tietoenator.com - 28 Jun 2007 14:38 GMT
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.
frodo2000@gmail.com - 28 Jun 2007 15:26 GMT
On 28 Cze, 15:38, "michael.schm...@tietoenator.com"
<michael.schm...@tietoenator.com> wrote:
> Hello,
>
[quoted text clipped - 70 lines]
> 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,'','');
frodo2000@gmail.com - 28 Jun 2007 15:34 GMT
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
michael.schmitz@tietoenator.com - 28 Jun 2007 15:49 GMT
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.
Artur - 28 Jun 2007 20:35 GMT
On 28 Cze, 16:49, "michael.schm...@tietoenator.com"
<michael.schm...@tietoenator.com> wrote:
> Hello Marcin,
>
[quoted text clipped - 16 lines]
>
> 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
michael.schmitz@tietoenator.com - 29 Jun 2007 08:30 GMT
> On 28 Cze, 16:49, "michael.schm...@tietoenator.com"
>
[quoted text clipped - 26 lines]
>
> -- 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).
michael.schmitz@tietoenator.com - 29 Jun 2007 08:57 GMT
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;
Artur - 29 Jun 2007 09:41 GMT
On 29 Cze, 09:30, "michael.schm...@tietoenator.com"
<michael.schm...@tietoenator.com> wrote:

> > On 28 Cze, 16:49, "michael.schm...@tietoenator.com"
>
[quoted text clipped - 32 lines]
> via TotalCommander) from a remote node via ODBC or JDBC (using Aqua
> Data Studio).

Sounds new for me. Here is information about DB2 PE in documentation:

http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/st
art/c0008740.htm


"DB2(R) Personal Edition is a single-user version of DB2. It can be
used to create and manage local databases, or as a client to connect
to DB2 database servers as well as DB2 Connect(TM) servers."

-- Artur Wronski
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.