Page 1 of 1

One DB2cmd instance

Posted: Thu Apr 10, 2003 1:29 am
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

Posted: Thu Apr 10, 2003 1:48 am
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);
?>

Using One DB2CMD instance

Posted: Thu Apr 10, 2003 4:54 am
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);
?>

Posted: Thu Apr 10, 2003 5:34 am
by volka
hm, maybe writing a cmd.File and execute it. Bad idea, hopefully someone else has a better solution :)