Upgraded to php 4.2.1, broke a script

David P. Schwartz plug-discuss@lists.plug.phoenix.az.us
Thu, 16 May 2002 00:34:09 -0700


Question:

Are the following two statements really equivalent?

1) echo "select binary_junk, filetype from images where img_id = '92'"

2) $get_image = "select binary_junk, filetype from images where img_id =
'$imgid'";

In particular, you might try doing an echo "$get_image" and see what shows up.

In regular scripts, '$imgid' != '92'.  I've had problems with MySQL queries
occassionally behaving similarly.  You could try changing those single-quotes
to escaped double-quotes:

$get_image = "select binary_junk, filetype from images where img_id =
\"$imgid\"";

-David

> Date: Wed, 15 May 2002 19:32:44 -0700
> From: "Kevin Brown"
> To: plug-discuss@lists.plug.phoenix.az.us
> Subject: Re: Upgraded to php 4.2.1, broke a script
> Reply-To: plug-discuss@lists.plug.phoenix.az.us
>
> > > Tried posting this to the php list last week, but it went down and hasn't come
> > > back since.
> > >
> > > Just upgraded the php on my poor little DEC Alpha multia that is running on the
> > > internal network here and it broke one of my php pages that pulls an image from
> > > a db and displays it (yes I know, poor performance).  The script was working as
> > > is with 4.1.2.
> > >
> > > show_image.php:
> > >
> > >
> > >
> > > Sample call: http://10.0.0.120/movies/show_image.php?imgid=92
> > >
> > > output from it is:
> > >
> > > Warning: Unable to jump to row 0 on MySQL result index 2 in
> > > /home/httpd/html/movies/show_image.php on line 8
> >
> > First, make sure you got a result, then make sure there's data in it.
> >
> > $get_image_result = mysql_query($get_image);
> > if( $get_image_result ) {
> >         $num_rows = mysql_num_rows( $get_image_result );
> >         if ( $num_rows > 0 ) {
> >                 // got results
> >                 // do stuff
> >         } else {
> >                 // didn't get results
> >                 // catch error
> >         }
> > }
> >
> > Have you tried the query from msql ( I think that's the name, it's psql for
> > the postgreSQL version )?
>
> OK, tried it with the error checking if then statements.  I'm not getting any
> results back from the database, but if I run the exact same command via the
> command line I get back a good result from the db.
>
> echo "select binary_junk, filetype from images where img_id = '92'" | mysql -u
> root movies > /tmp/mysqloutput
>
> The image ID is a unique number.  Only thing I can think is that something
> changed regarding the mysql connection functions.  Saw that 4.2.1 had a fix for
> 4.2.0 regarding connecting to a mysql db, so maybe there are other issues.
>
> Still find it funny that only the page that gets images is broken when all the
> other pages are displaying correctly.
>