I have a problem to make an UPDATE request using PDO.
I have a problem in my syntax somewhere but i don't know where..
Here is my code :
<?php
$PARAM_hote='aaaaaaaa';
$PARAM_port='3306';
$PARAM_nom_bd='bbbbbbbbbbb';
$PARAM_utilisateur='cccccccccccccc';
$PARAM_mot_passe='ddddddddddd';
// Create connexion to BDD
$connexion = new PDO('mysql:host='.$PARAM_hote.';port='.$PARAM_port.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe);
try {
$idAnnonce = $_POST['idAnnonce'];
$sqlUpdate = "UPDATE `annonces` SET `etat` = `offline` WHERE `id` = :idAnnonce ";
$resultats = $connexion->prepare($sqlUpdate);
$resultats->bindValue(':idAnnonce', $idAnnonce, PDO::PARAM_INT);
$resultats->execute();
// Check if request is success
echo $resultats->rowCount();
} catch(Exception $e) {
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
?>
Change
$sqlUpdate = "UPDATE `annonces` SET `etat` = `offline`...
to
$sqlUpdate = "UPDATE `annonces` SET `etat` = 'offline'...
Put quotes around "offline", and it should work.
I recently commented a similar..
set error mode for PDO as a:
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Only then you can catch all DB-errors with your try/catch block and see what's happen...
see doc: PDO::setAttribute