I don't understand why this code is not working. I can upload a photo and delete photos from my database when they are saved as BLOB but I can not update as a BLOB? This is the code I am using but I can not see what I am doing wrong.
try {
if (file_exists($imageFile)){
$photoToUpload = file_get_contents($imageFile);
$stmt = $db->prepare("UPDATE db_birds SET photo = :photoToUpload WHERE ID = :userID AND userName = :userName");
$stmt->execute(array(':photoToUpload' => $photoToUpload, ':ID' => $uid, 'userName' => $uname));
if (file_exists($imageFile)) (unlink($imageFile));
}
} catch( PDOException $e ) {
print_r($e);
}
This is the error I keep getting when trying to run the query.
PDOException Object ( [message:protected] => SQLSTATE[HY093]: Invalid parameter number: parameter was not defined [string:Exception:private] => [code:protected] => HY093 [file:protected] => C:\xampp\htdocs\admin\editadvert.php [line:protected] => 250 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\admin\editadvert.php [line] => 250 [function] => execute [class] => PDOStatement [type] => -> [args] => Array ( [0] => Array ( [:photoToUpload] => ����JFIF``��>CREATOR: gd-jpeg v1.0 (using IJG JPEG v90), default quality
I have tried everything I can think of but to no avail so I thought I would ask for help.
EDIT: I found another solution which worked for me. This is my solution...
try {
if (file_exists($imageFile)){
$photo = file_get_contents($imageFile);
$query="UPDATE db_birds SET photo=:photo
WHERE ID=:ID";
$step=$db->prepare($query);
$step->bindParam(':ID',$keys,PDO::PARAM_INT, 3);
$step->bindParam(':photo',$photo,PDO::PARAM_LOB);
$step->execute();
}
} catch( PDOException $e ) {
//print_r($e);
die();
}