I am writing an Apache module that has to perform some queries against a
MySQL database.  For the most part, it is working properly.  However, when I
get an empty result set for my query (that is, the select returns no rows) I
get a segmentation fault when trying to call mysql_num_rows.

Here is the relevant part of my code:


  if (mysql_query(mysql_handle, query) != 0) {
    .bail out.
  }
result=mysql_store_result(mysql_handle);
if (result) {
  if (mysql_num_rows(result) == 1){
    .process the row.
  }
}

The segfault occurs during the call to mysql_num_rows.

I have also tried using mysql_affected_rows(mysql_handle) instead; this call
also segfaults.

Finally, I have tried mysql_use_result like this:

result = mysql_use_result(mysql_handle);
if (result) {
  if (data = mysql_fetch_row(result)){
    .process data.
  }
}

And, you guessed it, the call to mysql_fetch_row segfaults.

If I isolate the MySQL code in a small test program (not an Apache module)
it works great.  I'm guessing it has something to do with either Apache or
PHP, which I also have included as a DSO in Apache.  I noticed the warning
about using the bundled MySQL support with PHP, so I re-compiled PHP using
the same libmysqlclient as my module - no change.

It seems as if mysql_[store/use]_result is returning a bad pointer when
there is an empty result set, but only inside an Apache module.  If the
query returns rows, everything works fine - I can verify this by
inserting/deleting rows from the database and watching httpd either live or
die.  I'm using 3.23.32-log on Linux.  Any thoughts?



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to