Saturday, 7 September 2013

PDO query can't be executed when trying to upload an image to the mysql database

PDO query can't be executed when trying to upload an image to the mysql
database

I am trying to add a picture into my mysql databse using the PDO queries.
It fails to execute the query and "failed to add the picture" is displayed
in the web browser. I get the following error message: Array ( [0] =>
HY093 [1] => [2] => ) MySQL error 1 When executing
Here is the code that I am using:
$email='test@yahoo.com';
$image=addslashes(file_get_contents($_FILES["image"]["tmp_name"]));
$sth = $dbh->prepare("UPDATE user SET driver_img = : driver_img WHERE
email = :email ");
$sth->bindParam(':email', $email, PDO::PARAM_STR, 100);
$sth->bindParam(':driver_img', $image, PDO::PARAM_LOB);
if($sth->execute()) {
echo "Managed to add the picture.";
}
else {
echo "failed to add the picture.";
$arr = $sth->errorInfo();
die("MySQL error <br>". print_r($arr) ."<br>When executing ");
}
The name of my database table is user. The attributes I am trying to
change are called driver_img and email.
Does anyone know what's wrong. Why can't the query be executed?

No comments:

Post a Comment