Hi,

Thanks for the help! My function is now working with the workaround.

Bye
Claus

> Hi,
>
> Since MaxDB PHP uses unbuffered result sets, all subsequent calls to
> maxdb_query() will return the out of sync error. This is due to
> compatibility with MySQL's mysqli extension which forbids more than one
> unbuffered result set.
>
> The problem in your program is that maxdb_free_result() will be called
> after the recursion finishes. In the meantime there are several calls to
> maxdb_query() without a maxdb_free_result() between them.
>
> It is a TODO to allow several open result sets with maxdb_query(). We
> will inform you when this feature is available.
>
> As a workaround you can use prepared statements like in the following
> simplified example:
>
> $leaf = /* ... */;
> $stmt = maxdb_prepare($db_connection, "SELECT id, data FROM datatree
> WHERE parent=?");
>
> function process_data ($db_connection, $stmt, $leaf) {
>
>   maxdb_stmt_bind_param($stmt, "s", $leaf);
>   maxdb_stmt_execute ($stmt);
>   maxdb_stmt_bind_result($stmt, $id, $data);
>   while (maxdb_stmt_fetch($stmt)) {
>     use_data (/*...*/);
>     /* ... */
>   }
> }
>
> process_data($db_connection, $stmt, $leaf);
>
> maxdb_stmt_close($stmt);
>
>
> Regards,
>
> Thomas
>
> -----Original Message-----
> From: Claus Windeler [mailto:[EMAIL PROTECTED]
> Sent: Mittwoch, 9. Februar 2005 14:01
> To: Simenec, Thomas
> Cc: [email protected]
> Subject: RE: PHP problem mith maxdb_query() and maxdb_real_query()
>
> Hello!
>
> Sorry, I forgot to write it when I simplified the code. In the real code
> I wrote
>
> If ($result = maxdb_query($db_connection, $sql)) {
>
> /*....*/
>
> }
>
> resulting in the mentioned error. Seems I can't use maxdb_query in a
> recursive
> function ?? ... it worked when I used ODBC driver.
>
>
> Bye
> Claus
>
> > 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]
> >
> >
>
>
>
>
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
>
>




-------------------------------------------------
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]

Reply via email to