mrmonkey
mrmonkey

Reputation: 3

Replacing a string with pdo on MySQL

I want to replace a string but I use PDO. Whatever I have tried is not working. Have you ever replaced a mysql string by using PDO connection?

Here is an example which is not working.

try
{
    $image = $_POST['data1'];
    $id= $_POST['data2'];


    $insert = "UPDATE myTable SET images=REPLACE(images,':image','') where id = :id";

    $insertStmt = $conn->prepare($insert);
    $insertStmt->bindValue(":image", $image);
    $insertStmt->bindValue(":id", $id);

        $insertStmt->execute();

        echo "success";
}

        catch(PDOException $ex)
{
        echo $ex->getMessage();
}

Upvotes: 0

Views: 471

Answers (1)

Friedrich Kölbel
Friedrich Kölbel

Reputation: 111

write :image instead of ':image'

$insert = "UPDATE myTable SET images=REPLACE(images,:image,'') where id = :id";

Upvotes: 1

Related Questions