LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-10-2004, 03:19 AM   #1
ukjairaj
Member
 
Registered: Jun 2004
Location: Mumbai-India
Distribution: RHEL-4 Update 2 & Fedore Core 5
Posts: 40

Rep: Reputation: 15
Question How to pass arguments from $prompt for php script


Dear Friends

I am a new bie for Linux and php. I just learning it with the help of various books.

I want to know how I can pass arguments to php script from command prompt.

For example: my php script should add two numbers that is given by user when he runs the script.

An example will help me to a great extent.

I am using Linux 9.00

This is why I want this script:
--------------------------------------

My practical need is to add a data to MySQL database, from a cobol program.
I felt i can call a php script from my cobol program passing the values to be merged in MySQL database, and the rest will be taken care by PHP script.

But I dont know how to pass values to php script when called by cobol program. I can do this if I know, how values are passed to php script when it fired from $prompt.

Like to learn more from this forum. Like to use this to a great extent



Jeyaraj
 
Old 06-10-2004, 04:43 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
#!/usr/bin/php -q
<?php
echo 'Number of arguments passed:' , $_SERVER['argc'] , "\n";
$count = 0;
foreach ($_SERVER['argv'] as $arg)
echo "argv[".$count++."]:$arg\n";
?>


and run as
./test.php one two three

anyway i didnt understand why you need php just to add values to mysql database.

PS: this thread should be in the programming section.
 
Old 06-17-2004, 02:24 AM   #3
ukjairaj
Member
 
Registered: Jun 2004
Location: Mumbai-India
Distribution: RHEL-4 Update 2 & Fedore Core 5
Posts: 40

Original Poster
Rep: Reputation: 15
How to pass arguments

Thanks zeropash for the clarification.

I could pass the value from $prompt and could get it displayed too., in one of my server.

i used this script

<?php
echo "Number of arguments passed: ";
echo $argc;
echo "\n";
echo "The argument is : ";
echo $argv[1];
echo "\n";
?>


It worked fine.

But it did not work in my another server. When i checked the php version, i came to know the script is working where I have php version 4.3.2 and not working with php version 4.2.2

But the script you gave worked really fine in both the version.

But, I dont know how to get the values of argv in php version 4.2.2

Exactly i want to replace the echo $argv[1] and $echo argc in the above mentioned script with suitable syntax, so that it will work fine in php version 4.2.2 too.

And about why I want php to insert data into MySQL database.

I want insert database into mysql table from COBOL program. I am using MF-COBOL in RedHat Linux-9.
My idea is to write a php script to insert data into MySQL database and call that php script from cobol program and pass the value to the script which will be inserted into MySQL table. If there is anyother better idea, kindly let me know.

Regarding this thread to be in programming section. Very sorry for it, in future i will start the thread in appropriate section.

Kindly help me in this regard.
 
Old 06-17-2004, 03:18 AM   #4
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
Re: How to pass arguments

[QUOTE]Originally posted by ukjairaj
[B]Thanks zeropash for the clarification.

But, I dont know how to get the values of argv in php version 4.2.2

#!/usr/bin/php
<?php
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];

echo "Number of arguments passed: ";
echo $argc;
echo "\n";
echo "The argument is : ";
echo $argv[1] ."\n";
?>

is this what you are looking for? I use 4.2.2 so I dont know about using those $argc directly
I dont know much about cobol. mysql has a C API too. so if there is a method to call C API;s from cobol you could use it right?
yeah you can use that php stuff .
 
Old 06-25-2004, 11:14 AM   #5
ukjairaj
Member
 
Registered: Jun 2004
Location: Mumbai-India
Distribution: RHEL-4 Update 2 & Fedore Core 5
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks zeropash, I was able to do that succesfully.

In fact i was able to fire the php query from my cobol program and insert the data into mysql database.

Let me ask you one thing, I want to know whether postgres commands can be direcly fired from MF-COBOL under Linux platform, to access the database.

Which category of this forum is appropriate to clear this doubt.

Jeyaraj K
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a row to another PHP script bahadur Programming 5 12-24-2011 01:07 AM
How to pass structure as function arguments ssg14j Programming 2 08-20-2005 09:59 PM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM
How can we pass arguments to installpkg ? frenchi Slackware 3 04-23-2004 06:43 PM
wine doesn't pass arguments correctly when calling programs jonchapman Linux - Software 0 10-08-2003 01:56 PM


All times are GMT -5. The time now is 01:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration