Re: [Phplib-users] HELP! php-mysql weirdness
Brought to you by:
nhruby,
richardarcher
|
From: nathan r. h. <na...@ds...> - 2001-09-20 20:18:30
|
On Thu, 20 Sep 2001, Stephen Woodbridge wrote:
> Thanks. Yes, that is what I did do, but all the books I have say to use:
>
> while($row = mysql_fetch_array($result)) {
> ...
> }
>
> to fetch rows but this construct does not work reliably if (my guess is
> if $row[0]=NULL) it can arbitrary fail based on the data set being
> fetched. It is a hidden and silent failure based on data. this construct
> is a poor one to tesch people to use as compared to something more ugly
> but reliable like:
>
> $num = mysql_num_rows($result);
> for ($i=0; $i<$num; $i++) {
> $row = mysql_fetch_array($result);
> ...
> }
>
Well, it's reliable so long as you know your data doesn't contain any NULL
vaules :) I think part of the issue is that your tables aren't
normalized, or at least, you're not filling in default vaules. You can
always rectifiy this by adding NOT NULL or by selecting a field that is
garunteed to return data (like selecting the primary key as well, though
shouldn't be too much of a speed hit, as it's well indexed)
Whipping through the result set with a for() loop is certianly another way
to go; however, as stated in the phplib manual, this doesn't work for all
DB's as they may start returning data before the query is finished. It
does work for MySQL though, and in this case, that's what counts.
> Sorry, I'm just frustrated after spending 3.5 hours trying to track this
> down when I was just trying a trivial experiment in my existing app. I
> think I need to review all my existing code to see if this might be
> happening elsewhere <sigh>
>
Understandable. It's always the little stuff that bugs me the most.
-n
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
nathan hruby / digital statement
na...@ds...
http://www.dstatement.com/
Public GPG key can be found at:
http://www.dstatement.com/nathan-gpg-key.txt
ED54 9A5E 132D BD01 9103 EEF3 E1B9 4738 EC90 801B
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|