Solved

PHP script dying...why?

Posted on 2007-04-11
6
269 Views
Last Modified: 2012-05-05
I have a function looking like this:

function remove_tree($tid){
    $Q = "DELETE FROM tree WHERE Id = $tid";
    $R = mysql_query($Q);
    $Q2 = "SELECT * FROM tree_member WHERE tree_id = $tid";
    $R2 = mysql_query($Q2);
    while($rec = mysql_fetch_object($R2)){
        echo "deleting indi:".$rec->individual_id;
        del_indi($rec->individual_id, 1);
    }
    echo "OK";
}

As long as I comment out the call to del_indi everything is ok, but when the call is in there the script never reaches the echo "OK".
I have tried with commenting out everything inside the del_indi function which otherwise is working ok when called directly, but still the issue remains, the script will stop executing as long as the call is there.

The del_indi function is now looking like this:

function del_indi($id, $silent) {
    echo "deleting:".$id;
}

I never recive the echo from del_indi.
The MySQL statements is working ok (the correct row in table "tree" is deleted and echo "deleting indi" returns the right id).

PHP Version is 5.1.2
0
Comment
Question by:Blixtsystems
  • 4
6 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 65 total points
ID: 18889715
>> The del_indi function is now looking "like" this:

Is the function you listed here 'exactly' what is listed in your code, or is it 'like' the one that is actually in use? I notice that the function has a $silent flag, and I wonder if that is coming into play here.
0
 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889782
There used to be code in there, but I stripped it out for testing for now.

I made an even more stripped down version:

      function main(){
            echo "main";
            //test();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

That will return "mainOK"

However:

      function main(){
            echo "main";
            test();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

will return only "main"

The functions is inside a class instantiated in engine.php like this:

require_once('classes/engine.class.php');
$engine = new engine();
$engine->main();
0
 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889811
Sorry that should be:

      function main(){
            echo "main";
            sub();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

Result is the same however
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889897
ok...I figured it was a scope issue of some sort and is used to having the scope of the class accessible inside the function.
But apparently I need a $this->sub()
0
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 60 total points
ID: 18889899
Try adding a return; to the sub.

like this

function main(){
 echo "main";
 sub();
 echo "OK";
      }

function sub(){
   echo "sub";
   return;
}
0
 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889960
It was simply a scope issue like I explained above.
Since I'm new to this site I'm not sure what to do when I solved the issue myself, so I'll just give you guys the points for your effort.
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now