Unix Technical Forum

Re: how to connect to DB2-Server

This is a discussion on Re: how to connect to DB2-Server within the DB2 forums, part of the Database Server Software category; --> On Wed, 20 Aug 2003 13:51:35 +0200, Andreas Korthaus wrote: > Hi! > > The configuration of a client ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 02:33 PM
Philip Nelson
 
Posts: n/a
Default Re: how to connect to DB2-Server

On Wed, 20 Aug 2003 13:51:35 +0200, Andreas Korthaus wrote:

> Hi!
>
> The configuration of a client to comunicate with a DB2 Server seems to be
> very difficult. But I do not need to connect over the network, I would like
> to use a simple Commandline-Client on the server-machine, where I can
> connect by SSH. I do not want DB2-Server to listen to external connections,
> I only need it on localhost. What I want to do is to use DB2-Server from
> PHP. To set up PHP with DB2-support is no problem, but I do not know what I
> have to do on DB2-Site. I used manual-unstall (db_install-Scrpt) and
> configured DB 2 like this(in shell):
>
> /opt/IBM/db2/V8.1/instance/dascrt -u db2as
> /opt/IBM/db2/V8.1/instance/db2icrt -a server -u db2fenc1 db2inst1
> /opt/IBM/db2/V8.1/cfg/db2ln
>
> What do I need now to connect from my PHP-application? I have to build a
> databse and a user for PHP, how could I do this? Which admin-tool would you
> recommend? I have no X installed(runlevel 3), and the server located in a
> datacenter far away from here.
>
> Thank You!
>
> kind regards,
> Andreas Korthaus
>
> PS: a license-question: do I need an own server-licence for each database or
> only for each server-installation?


Andreas,

I assume you are able to start the DB2 instance you've created.

If so then you need to add the db2profile script into your login script to
set up the DB2 environment. Assuming the DB2 instance owner home
directory is /home/db2inst1 then you'd add the following (for bash) -

.. /home/db2inst1/sqllib/db2profile

You will then be able to run commands like -

db2 "connect to dbname"

assuming you have authority to do so.

To give a user SYSADM authority add him to the group db2iadm1.

The licence is for servers, not for individual dbs.

HTH

Phil
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 02:33 PM
Andreas Korthaus
 
Posts: n/a
Default Connect from PHP: SQL error: [IBM][CLI Driver] SQLSTATE=58004

Hi Philip,

Philip Nelson wrote:
> I assume you are able to start the DB2 instance you've created.


I don't realy know. I did not start anything, but by using
"db2"-commandline-tool I can create databases, insert sata, select data...

But how sould I start? I tried

db2 => connect to test

Database Connection Information

Database server = DB2/LINUX 8.1.0
SQL authorization ID = DB2INST1
Local database alias = TEST

db2 => db2start
SQL1026N The database manager is already active.
db2 => db2stop
SQL1025N The database manager was not stopped because databases are still
active.
db2 =>

I created the database "test", and I could do inserts and updates:

db2 => select * from person

NAME
------------------------------
testname

1 record(s) selected.


But I did not anything else. I only used db2_install and the 3
shell-commands as mentioned before, to configure the server. I did not make
anything with a client, I did not configure the comunication between server
and client, and I did not use "Catalog" in the client. As it worked as above
I thought it was not necessary. I use db2 Client and Server on the same
machine, and all manuals I read described how to connect from a GUI-Client,
that's not what I want. I Think I have to connect form the CLI-client to the
server, and therefore I have to configure client _and_ server, right? But
what should I configure and how? I have no access with any GUI-client, I
would like to use the shell, because the server has no X installed (runlevel
3).

I want to use DB2 for a PHP-Project, there I tried the following PHP-Code:

<?php
$dbname = "TEST";
$username = "db2inst1";
$password = "andreas";

// odbc_connect returns 0 if the connection attempt fails;
// otherwise it returns a connection ID used by other ODBC functions
$dbconn = odbc_connect($dbname, $username, $password);

$sqlerror = odbc_errormsg($dbconn);
echo($sqlerror);
?>

If I run this script I get the Error:

Warning: SQL error: [IBM][CLI Driver] SQLSTATE=58004, SQL state 58004 in
SQLConnect in /home/www/easy-procure/live/http-root/admin/db2.php on line 9

(PHP es configured correct with DB2-Support)


> . /home/db2inst1/sqllib/db2profile


Yes, that made the Error-Message above visable, befor there was something
like

Warning: SQL error: |}!A, SQL state $E+F+?E+ýÿÿÿýÿÿÿýÿÿÿÈÈÿ¿Éÿ¿ in
SQLConnect in /home/www/test/db2.php on line 9

> You will then be able to run commands like -
>
> db2 "connect to dbname"


Yes, but this was also possible before

> To give a user SYSADM authority add him to the group db2iadm1.


So all "DB-Users" are also "System-Users"?

I have no experience with a DB-Server as DB2 or Oracle, only with MySQL,
PostgreSQL, and they are more simple.

Perhaps someone has an idea what to do that I can connect from PHP, or how
to set up the communication between Client und Server, if still necessary.

Thank You very much for your help!


Kind regards,
Andreas


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 02:34 PM
Andreas Korthaus
 
Posts: n/a
Default problem solved

Hi!

> If I run this script I get the Error:
>
> Warning: SQL error: [IBM][CLI Driver] SQLSTATE=58004, SQL state 58004
> in SQLConnect in /home/www/easy-procure/live/http-root/admin/db2.php
> on line 9
>
> (PHP es configured correct with DB2-Support)
>
>
>> . /home/db2inst1/sqllib/db2profile


It was not enough to execute the Script from shell where I execute
apachectl, I had to build this into apachectl script, now it works great!


Thank You!

Andreas


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:58 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com