cesarcesar wrote:Do you have an example i can work off of?
A rough equivalent would be something like this:
/* connect to the database (works) */
$dbHandle = new PDO('sqlite:' . $CFG->baseroot . '/db/mmt.db3');
$dbHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbHandle->prepare('SELECT first_name FROM user WHERE id = :id');
$stmt->bindParam(':id', 5);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($user['name'] == 'John') {
$stmt = $dbHandle->prepare('UPDATE user SET last_name = :lastname WHERE first_name = :firstname');
$stmt->bindParam(':lastname', 'Doe');
$stmt->bindParam(':firstname', 'John');
$stmt->execute();
}
The prepared statements are not strictly necessary, but you probably won't want to fix those values anyway. Incidentally, note that I changed it such that an exception will be thrown on a database error; this may help you diagnose your current problem if it still occurs.
However, if you are only retrieving in order to update, then you might as well just update as in katsurace's example.
katsurace wrote:i think its not a good idea to make changes when db is in read only state, it directly breaks the law of serializability also called conflict serializability.
hmm... but shouldn't the database be no longer in a read only state once the previous statement has finished execution?