[PHPLIB] db_odbc.inc, table.inc and num_rows vagaries From: Michael Anthon (mca <email protected>)
Date: 03/03/00

I have just managed to fix a few problems that I encountered while
setting up PHPLIB 7.3, PHP 3.0.14 and Personal Web Server on a Win98
box, talking to a remote MS SQL 6.5 server via ODBC.. (I know it's evil,
but I just had to try it) and I thought I would report the issues I ran
into and what I did to fix them. There is something odd in one section
that I cannot explain and I was hoping someone might be able to explain
what is happening.

1. Executing stored procedures.

As shipped, db_odbc.inc does not allow the execution of stored
procedures on the server. When subclassing the DB_Sql, set
  var $UseODBCCursor = 1;
I'm not sure if this is documented anywhere, but I did not find it. I
had previously played with executing stored procedures so I knew what to
look for to fix this.

2. Using Table->show_result and Table->show_result_page in table.inc

Initially I could not get these to work. After a bit of debugging I
discovered that DB_Sql->num_rows() was only returning the correct number
of rows on the first call to it, thereafter it would return 0. Since
this function is called multiple time from within the Table class, this
was causing it to fail miserably.

I have modified DB->Sql as follows

Added 'var $RecordCount = 0;' to the class variables

Added the following as the first line in DB_Sql->query()
          $this->$RecordCount=-1;

Added the following at the start of DB_Sql->num_rows()
        if ($this->$RecordCount<>-1)
                return $this->$RecordCount;

I suspect that this change may also have some performance benefits for
other ODBC drivers, but I'm not really sure.

This is where things got a little strange. Calling the
DB_Sql->num_rows() function from within my main program file, everything
worked as expected. AS soon as I removed the debug lines that called
this function the show_result* functions broke again. After a bit more
tracing, I found that the $RecordCount variable was being set, but was
not retaining the new value when it was called from wihtin
Table->verify_db(). This is the bit that I cannot work out. Why does
the variable not retain the value?
The call stack at this point is
    mycode, Table->show_result, Table->verify(db), DB_Sql->num_rows().

 I have added the line '$db->num_rows();' as the first line in
show_result and show_result_page and this has fixed it. This makes the
call stack
    mycode, Table->show_result, DB_Sql->num_rows().

Is this something to do with the depth of the nesting in the function
calls? I can't really tell

Anyway, after doing those few minor changes, everything else seems to
work perfectly !!

Cheers
Michael Anthon
-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.