One DB2cmd instance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vram
Forum Newbie
Posts: 9
Joined: Tue Apr 08, 2003 3:58 am

One DB2cmd instance

Post by vram »

Hi friends
I execute db2 commands thru a webpage using PHP script..For executing db2 commands ,i need to call db2cmd

everytime like this to initialise command line environment.
<?php Start of PHP
//Initialised session
..
.
system('db2cmd /c /w /i db2 get instance');
system('db2cmd /c /w /i db2 connect to sample');
system('db2cmd /c /w /i db2 select * from staff');
.
.
//Close the session
?> End of PHP

The problem here is the commands getting executed in separate environments which gives erroneous o/p
ie after connecting to sample database,i tried to select the values from the table staff,I get this error
"Database connection does not exist". Anybody pls tell me how to initialise command line envoironment once and execute db2 commands in it until i terminate from the enviroment.Thanx in advance.
Bye
With regards
Vram
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
...
$cmd = 'db2cmd /c /w /i db2 get instance';
$cmd .= ' && db2cmd /c /w /i db2 connect to sample'; 
$cmd .= '&& db2cmd /c /w /i db2 select * from staff';
...
system($cmd);
?>
vram
Forum Newbie
Posts: 9
Joined: Tue Apr 08, 2003 3:58 am

Using One DB2CMD instance

Post by vram »

Hi
It is not working.Tell me any another option. Bye
Thanx in advance.



volka wrote:try

Code: Select all

<?php
...
$cmd = 'db2cmd /c /w /i db2 get instance';
$cmd .= ' && db2cmd /c /w /i db2 connect to sample'; 
$cmd .= '&& db2cmd /c /w /i db2 select * from staff';
...
system($cmd);
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, maybe writing a cmd.File and execute it. Bad idea, hopefully someone else has a better solution :)
Post Reply