pdo UPDATE does not work

I'm trying to send some values to SQL, but PDO doesn't work as it should, or I'm forgetting something, I'm new to using PDO.

Functional code example.

    $conn = new PDO('mysql:dbname=config_database;host=127.0.0.1', 'root', '');
    $statement = $conn->prepare("UPDATE stream_table SET src='Funcional' WHERE start = '60'");
    $statement->execute();

Non-functional code example.(I tried several other possibilities without success) (Does not return error, just does nothing)

    $conn = new PDO('mysql:dbname=config_database;host=127.0.0.1', 'root', '');
    //$value = $_POST['value'];              //A ideia real é pegar via POST
    $value = 'C:\sample.code';               //Simplificando o test
    $statement = $conn->prepare("UPDATE stream_table SET src='?' WHERE start = '60'");
    $statement->bindValue(":value", $value); //Testei com bindParam e bindValue
    $statement->execute();

I do not know if it is due to apostrophe or something else, I followed several examples contained on the internet and it does not even work, it is evil .

How can I execute this command functionally?

Maybe this post here from SO-pt will help.

@Edit

Error note: I cannot use placeholders to name tables or columns.

 0
Author: Comunidade, 2014-06-11

1 answers

When using ? in bindValue put the order of the argument and variable:

$statement = $conn->prepare("UPDATE stream_table SET src = ? WHERE start = ? ");
$statement->bindValue(1, $value);
$statement->bindValue(2, $id);

With the markings (:nome) the order does not matter

$statement = $conn->prepare("UPDATE stream_table SET src = :value WHERE start = :id ");
$statement->bindValue(':id', $id);
$statement->bindValue(':value', $value);

To display the error add the optional argument in the constructor in addition to PDO::ERRMODE_EXCEPTION exitem other ways to treat the error.

$options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
$conn = new PDO('mysql:dbname=config_database;host=127.0.0.1', 'root', '', $options);

try {
   //....
   $statement->execute();
} catch(Exception $e) {
   echo $e->getMessage();
}
 4
Author: rray, 2014-06-11 19:42:02