List:General Discussion« Previous MessageNext Message »
From:Pooly Date:September 18 2005 12:47pm
Subject:Re: mysql_free_result() WITHOUT mysql_fetch_row()
View as plain text  
2005/9/17, Miguel Cardenas <renito73@stripped>:
> > In the last episode (Sep 17), Miguel Cardenas said:
> > > I have a technical doubt, very simple but not mentioned in the manual...
> > >
> > > What happens if I call mysql_free_result() after performing a query
> > > but without doing mysql_fetch_row() ???
> > >
> > > It may sound strange, but just need to know if a data row exists more
> > > than the data itself...
> >
> > A faster way would be to run a "SELECT count(*) WHERE ..." query, and
> > check the result.  Since you are not selecting any data, mysql is more
> > likely to be able to use index lookups to speed the query up.
> 
> Well, in fact don't want to check if there is data already inserted on the
> table to make condition TRUE, what I want is to do this:
> 
> SELECT id,data FROM table WHERE id=XXX
> 
> but, just want to check if it the search found something and then free the
> resources, not to retrieve the data... in short words:
> 
> 1. search rows which id=XXX
> 2. if mysql_num_rows() > 0 then CONDITION=TRUE else CONDITION=FALSE
> 3. mysql_free_result()
> 
> WHY? well, this operation will be repeated over 100,000 times and only need to
> know if the specified data exists, the difference between just know and
> retrieve 1 time and 100,000 times surely would be significative if I try
> 
> 1. search rows which id=XXX
> 2. if mysql_fetch_row() then CONDITION=TRUE else CONDITION=FALSE
> 3. mysql_free_result()
> 
> Specifically, my doubt is, what happen if I call mysql_free_result() if I
> don't call mysql_fetch_row() before, or if not all rows are read before
> calling it...

http://dev.mysql.com/doc/mysql/en/mysql-free-result.html
it does not says : you have to retrieve all rows before freing it. So
you should be able to free the result. Otherwise it's a bug or
undocumented behaviour.
But why don't you use the Count(*) solution ?? that's exactly what you
need IMHO.

-- 
Pooly
Webzine Rock : http://www.w-fenec.org/
Thread
mysql_free_result() WITHOUT mysql_fetch_row()Miguel Cardenas17 Sep
  • Re: mysql_free_result() WITHOUT mysql_fetch_row()Dan Nelson17 Sep
    • Re: mysql_free_result() WITHOUT mysql_fetch_row()Miguel Cardenas18 Sep
      • Re: mysql_free_result() WITHOUT mysql_fetch_row()Pooly18 Sep
        • Re: mysql_free_result() WITHOUT mysql_fetch_row()Miguel Cardenas18 Sep
          • Re: mysql_free_result() WITHOUT mysql_fetch_row()Pooly19 Sep
Re: mysql_free_result() WITHOUT mysql_fetch_row()Pooly19 Sep
  • Re: mysql_free_result() WITHOUT mysql_fetch_row()Miguel Cardenas19 Sep
    • Re: mysql_free_result() WITHOUT mysql_fetch_row()SGreen19 Sep