LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to pass arguments from $prompt for php script (https://www.linuxquestions.org/questions/linux-software-2/how-to-pass-arguments-from-%24prompt-for-php-script-191820/)

ukjairaj 06-10-2004 03:19 AM

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

zeropash 06-10-2004 04:43 AM

#!/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.

ukjairaj 06-17-2004 02:24 AM

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.

zeropash 06-17-2004 03:18 AM

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 .

ukjairaj 06-25-2004 11:14 AM

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


All times are GMT -5. The time now is 11:39 PM.