Jump to content

Help. I am going insane witha mysqli_prepare issue !!!


Recommended Posts

This is driving me NUTS!!!! and I can't figure it out or I am just burnt out. In a nut shell, I have a process that uploads a photo and inserts data into a table. Every single query on my site is prepared for security reasons. My issue is as follows.

 

I have two versions of a photograph. The 2nd version is just a cropped version of the original and save to be smaller in size. That is the only difference and using jhead confirms this.

 

So my prepared code looks like this

 

$query = "INSERT INTO photos VALUES (0, ?,?, unix_timestamp(),?,?,?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,NULL,NULL)";

 

$stmt = mysqli_prepare($connectstring, $query);

 

mysqli_stmt_bind_param($stmt, 'sississsssiisissiis', $title,$userid,$bigname,$smlname,$newfilesize,$camera,$cameramodel,

$focallength,$exposure,$aperture, $iso,$photocategoryid,$path,$active,$datetaken,$resolution,$autoexif,$lens,$medname);

 

So far so good.

 

If I upload the smaller of the two files, everything is fine. I echo the bind statement so I can see what goes on and here is what is going into the database just fine.

 

('sississsssiisissiis', ,4,U4I1306951247.SEQ.0.jpg,sml_U4I1306951247.SEQ.0.jpg,1594629,SONY,DSLR-A850,35mm, 0.0080 s (1/125),f/8, 200,9,gallery/4/,1, 2011:05:28 06:31:35, 2000 x 900,0,-1,med_U4I1306951247.SEQ.0.jpg)

 

Keep in mind no quotes around values because its prepared.

 

So I try the larger file with these values

 

('sississsssiisissiis', ,4,U4I1306951156.SEQ.0.jpg,sml_U4I1306951156.SEQ.0.jpg,3241103,SONY,DSLR-A850,35mm, 0.0080 s (1/125),f/8, 200,9,gallery/4/,1, 2011:05:28 06:31:35, 2000 x 1333,0,-1,med_U4I1306951156.SEQ.0.jpg)

 

And it bombs with these messages

 

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in ...

 

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in ...

 

Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in ...

 

Keep in mind, the file actually uploaded without any issues. it only fails on the prepared statement insert.

 

Any idea what is going on here? I have increased my max packet size in my.cnf as well but that does not help.

 

Is it so obvious that I am missing it?

 

Thanks

 

JT

Either your mysqli_prepare() is failing due to an error (do you have any error checking and error reporting logic in your code so that you would know if it works or not) or you are overwriting the $stmt variable at some point in your code.

if ($stmt = mysqli_prepare($connectstring, $query)) {

        mysqli_stmt_bind_param($stmt, 'sississsssiisissiis', $title,$userid,$bigname,$smlname,$newfilesize,$camera,$cameramodel,

                                $focallength,$exposure,$aperture, $iso,$photocategoryid,$path,$active,$datetaken,$resolution,$autoexif,$lens,$medname);

 

        if( ! mysqli_stmt_execute($stmt) ) {

            $x = mysqli_error ( $connectstring );

            mysqli_stmt_close($stmt);

            error_message($x);

        } else {

            $newphotoid = mysqli_insert_id($connectstring);

            mysqli_stmt_close($stmt);

        }

} else {

  echo "Oh no!";

}

 

 

 

I get an error "the prepared failed" I don't know why it errors out.

I figured out how to fix the problem but it still does not answer my question why almost two identical queries have different results in execution.

 

Anyway, I fixed it by setting

 

mysqli.recoonect = On

 

in php.ini

 

I still need to know why I lose connection. Any idea how to determine that?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.