php-general Digest 2 May 2011 08:55:26 -0000 Issue 7293

Topics (messages 312610 through 312618):

passing control to a separate script
        312610 by: Jim Giner
        312611 by: Stuart Dallas
        312613 by: Jim Giner
        312614 by: Stuart Dallas
        312615 by: tedd
        312618 by: Stuart Dallas

Re: postgresql database access failure
        312612 by: David Robley
        312616 by: e-letter
        312617 by: Florin Jurcovici

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
I have a large script that does a certain function for me.  I have a second 
script that gets called and does its thing and when I'm done with it I'd 
like to pass control to the first script.  I don't need this 'included' in 
my second script - I just want to pass control to it and let it take over 
again.

Is this do-able? 



--- End Message ---
--- Begin Message ---
On Monday, 2 May 2011 at 02:17, Jim Giner wrote:
I have a large script that does a certain function for me. I have a second 
> script that gets called and does its thing and when I'm done with it I'd 
> like to pass control to the first script. I don't need this 'included' in 
> my second script - I just want to pass control to it and let it take over 
> again.
> 
> Is this do-able?

To clarify, you have something like this...

one.php
---
echo 'do one thing';
// pass control to two.php
echo 'do another thing';
---

two.php
---
echo 'do something else';
// pass control back to one.php
---

If that's correct then simply include two.php from one.php, like so...

one.php
---
echo 'do one thing';
include 'two.php';
echo 'do another thing';
---

If not then I've misunderstood what you're after. Can you give us an example?

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/






--- End Message ---
--- Begin Message ---
No - I don't want to include either one in the other one.  They are separate 
things that interesect once.  I really am just trying to do this separately 
as I said.

script1
work
work
work
(done)

script2
do something
user response
do something (write data)
execute script 1
(done.

Script 2 doesn't need a response - no return to it.  I'm trying to keep from 
having the user interact with it one more time just to have a form & button 
that uses its' action= to run script 1. 



--- End Message ---
--- Begin Message ---
On Monday, 2 May 2011 at 02:44, Jim Giner wrote:
No - I don't want to include either one in the other one. They are separate 
> things that interesect once. I really am just trying to do this separately 
> as I said.
> 
> script1
> work
> work
> work
> (done)
> 
> script2
> do something
> user response
> do something (write data)
> execute script 1
> (done.
> 
> Script 2 doesn't need a response - no return to it. I'm trying to keep from 
> having the user interact with it one more time just to have a form & button 
> that uses its' action= to run script 1.

In script2 you have the user responding in the middle of execution - this is 
not possible. PHP runs a script and returns the output to the client. The user 
then takes action which may cause another PHP script to be executed. There is 
no way to pause execution of a web-based PHP script and wait for a user action.

In what you've given us above I'm unclear on how script1 and script2 interact 
with each other. Can you elaborate?

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/





--- End Message ---
--- Begin Message ---
At 9:17 PM -0400 5/1/11, Jim Giner wrote:
I have a large script that does a certain function for me.  I have a second
script that gets called and does its thing and when I'm done with it I'd
like to pass control to the first script.  I don't need this 'included' in
my second script - I just want to pass control to it and let it take over
again.

Is this do-able?

Yes, this is do-able.

But don't be afraid of the include statement.

Here's an example that can be easily made to do what you want:

http://www.webbytedd.com/bb/php-run-php/

After the first script runs, it includes the second script that then runs, which then includes the first script to continue.

If you don't want to use a $_POST to trigger the critter, then use location, such as:

// first script
if($to_second_script)
  {
   header('Location: http://www.example.com/second.php');
   exit();
   }

// second script
if($to_first_script)
  {
   header('Location: http://www.example.com/first.php');
   exit();
   }


Either those will work depending upon the trigger you need.

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On Monday, 2 May 2011 at 05:21, Jim Giner wrote:
Script 1 calls script 2. Script 2 has several paths in it which is how the 
> user gets to interact with it. Once the final path has been taken (data 
> gets written) I don't want to use script 2 any longer - I want script 1 to 
> begin, by a call from the "executing" script 2 that will initiate script 1 
> and then script 2 goes away since script 1 will have control. It's kind of 
> like passing a baton in a relay race.

You want script 1 to begin again? In that case simply include script1 from 
script2 then call exit immediately afterwards. The only way to make use of 
another script without it returning back to the current script once it's done 
is if that other script calls exit or die to end execution.

When you say script 1 "calls" script 2, what do you actually mean? Is it 
included, are you calling a function in script 2, or is the user clicking on a 
link / submitting a form that runs script 2?

To get "script 1 to begin" from script 2 based on a certain path...

script2.php
---
if ($path1)
{
// do stuff here
include('script1.php');
exit;
}
// otherwise do other stuff here
---

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/






--- End Message ---
--- Begin Message ---
e-letter wrote:

> The file was changed:
> 
> ...           $value=pg_fetch_result($query,1,1);
> echo 'all files' . var_dump($value);
> ...
> 
> The resultant web page produces:
> 
> bool(false) all files
> 
> The php file was changed again:
> 
> ...           $value=pg_fetch_result($query);
> echo 'all files' . var_dump($value);
> ...
> 
> The resultant web page produces:
> 
> NULL all files
> 
> The error log shows:
> 
> ...PHP Warning:  pg_fetch_result(): supplied argument is not a valid
> PostgreSQL result resource...
> 
> The objective is to learn how to extract data from a database and
> print to a web browser, but not much progress made so far..!

There is a good example of how to use pg_fetch_result in the docs at
http://php.net/manual/en/function.pg-fetch-result.php.

On the basis of the code shown here, it's a bit hard to determine exactly
what your problem is; however the odds are that the error "supplied
argument is not a valid PostgreSQL result resource" results from a SQL
syntax error, or possibly that you have failed to open a connection to
pgsql. However, there are some tools to help you; see
http://php.net/manual/en/function.pg-result-error.php

For future reference, it helps to post all the code that is relevant to your
problem, so in this case it would help, for example, to see how you are
making the connection to pgsql and how the $query variable is populated.



Cheers
-- 
David Robley

A seminar on Time Travel will be held two weeks ago.
Today is Boomtime, the 49th day of Discord in the YOLD 3177. 


--- End Message ---
--- Begin Message ---
The query was:

$query = 'SELECT * FROM databasetablename';

So, database access seems to be the problem. Using the superuser
account 'postgres', a user 'httpd' was created and all privileges were
granted to the target database using the postgresql 'grant' command.
However the user 'httpd' is not the owner of the database so perhaps
that is the problem, although if this user could not access the
database that would cause an error in the log (but no such error is
seen)?

--- End Message ---
--- Begin Message ---
Hi.

<?php
>                $db = pg_connect('dbname=webcuttings user=httpd');
>                $query = 'SELECT * FROM articles';
>                $value=pg_fetch_result($query);
>                echo 'all files' $value;
>        ?>

Maybe a password is set on your database for the user httpd?

You have to first call pg_query(), which actually performs the query,
storing the returned results into some internal buffer, in the
unprocessed form that they get returned from the database, and only
then call pg_fetch_result() to reformat and extract one row. The
manual says:

<?php
$db = pg_connect("dbname=users user=me") || die();
$res = pg_query($db, "SELECT 1 UNION ALL SELECT 2");
$val = pg_fetch_result($res, 1, 0);
echo "First field in the second row is: ", $val, "\n";
?>

What you do is calling pg_fetch_result() before any result is
available, since you didn't actually perform the query yet.

Here's the URL of the relevant manual page:
http://www.php.net/manual/en/function.pg-fetch-result.php

My personal recommendation, however, is to drop old-style procedural
drivers and switch to PDO - it's much more convenient to use, IMO. If
you use PDO, you don't need to study the API of various different DB
drivers, and your code can easily switch from one database to another.

br,

flj

--- End Message ---

Reply via email to