Hi,

For working on a result set with maxdb_fetch_assoc() you have to
retrieve the result set with maxdb_query() first.
The right way to write the if condition is

  If ($result = maxdb_query($db_connection, $sql)) {
    /* ... */
  }

Regards,

Thomas Simenec
SAP Labs Berlin

-----Original Message-----
From: Claus Windeler [mailto:[EMAIL PROTECTED] 
Sent: Mittwoch, 9. Februar 2005 13:01
To: [email protected]
Subject: PHP problem mith maxdb_query() and maxdb_real_query()



I have a recursive function to process data which is organized in a
tree. The
data is stored in a database.

I am using PHP 5 with MaxDB-Module 1.0

First I tried the following version of my function

function process_data($leaf) {

    $sql = 'SELECT id, data FROM datatree WHERE parent='.$leaf;

    if (maxdb_query($db_connection, $sql)) {

        while ($row = maxdb_fetch_assoc($result)) {

          use_data($row['DATA']);

           // check if childs should be processed. Not always true.
          if (process_childs($row['ID'])) process_data($row['ID']);

        }

        maxdb_free_result($result);

     }

}

This results in an maxdb_query error when function is called the second
time
during recursion:

function.maxdb-query: Commands out of sync. You can't use this command
now.


I modified the function to use maxdb_real_query():

function process_data($leaf) {

   $sql = 'SELECT id, data FROM datatree WHERE parent='.$leaf;

   if (maxdb_real_query($db_connection, $sql)) {

       $result = maxdb_store_result($db_connection);

       while ($row = maxdb_fetch_assoc($result)) {

           use_data($row['DATA']);

           if (process_childs($row['ID'])) process_data($row['ID']);

       }

       maxdb_free_result($result);

    }

}

When I execute it my Apache-Webserver hangs an I have to restart it.

Can someone show me the right way to implement the function or point me
to my
mistake ??

Bye
Claus Windeler


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/


-- 
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to