jtorral Posted June 1, 2011 Share Posted June 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238153-help-i-am-going-insane-witha-mysqli_prepare-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 1, 2011 Share Posted June 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238153-help-i-am-going-insane-witha-mysqli_prepare-issue/#findComment-1223805 Share on other sites More sharing options...
jtorral Posted June 1, 2011 Author Share Posted June 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238153-help-i-am-going-insane-witha-mysqli_prepare-issue/#findComment-1223811 Share on other sites More sharing options...
PFMaBiSmAd Posted June 2, 2011 Share Posted June 2, 2011 If you echo mysqli_error($connectstring) as part of your else{} statement, it should tell you why the mysqli_prepare failed. Quote Link to comment https://forums.phpfreaks.com/topic/238153-help-i-am-going-insane-witha-mysqli_prepare-issue/#findComment-1223821 Share on other sites More sharing options...
jtorral Posted June 2, 2011 Author Share Posted June 2, 2011 Oh yea. Did that. I get MySQL server has gone away. Quote Link to comment https://forums.phpfreaks.com/topic/238153-help-i-am-going-insane-witha-mysqli_prepare-issue/#findComment-1223825 Share on other sites More sharing options...
jtorral Posted June 2, 2011 Author Share Posted June 2, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238153-help-i-am-going-insane-witha-mysqli_prepare-issue/#findComment-1223852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.