Persons table has a field called "data" and another field called "id" that is automatically incremented. It has 1 entry and I am trying to update that entry. I am using GAE Cloud Sql for php. I successfully connect to the database then do the following:
$data="Please do not go.";
try {
$stmt = $db->prepare('INSERT INTO Persons (data) VALUES (:theData)');
$stmt->execute(array(':theData' => htmlspecialchars($data)));
$affected_rows = $stmt->rowCount();
// Log $affected_rows.
} catch (PDOException $ex) {
// Log error.
die(json_encode(
array('outcome' => false, 'message' => 'PIE.')
)
);
}
$data="Please go away.";
try {
$stmt = $db->prepare('UPDATE Persons (data) VALUES (:theData) WHERE id=1');
$stmt->execute(array(':theData' => htmlspecialchars($data)));
} catch (PDOException $ex) {
// Log error.
die(json_encode(
array('outcome' => false, 'message' => 'LOL YOU FAILED')
)
);
}
foreach($db->query('SELECT * from Persons') as $row) {
echo $row['data'];
}
$db = null;
The output is:
Please do not go.
Instead of:
Please go away.
What is wrong with the code I use to UPDATE the table?