Solved

PHP script dying...why?

Posted on 2007-04-11
6
278 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 count occurrences of each item in an array.

773 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