我尝试使用行的id删除行,但我的脚本不起作用。 有没有语法错误?
<?php
$PARAM_hote='aaaaaaa';
$PARAM_port='3306';
$PARAM_nom_bd='bbbbbbbbb';
$PARAM_utilisateur='cccccccccc';
$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 {
$id = $_POST['id'];
// Prepare SQL request to check if the user is in BDD
$sqlInsert = 'DELETE from annonces where id=:id';
$resultats = $connexion->prepare($sqlInsert);
$resultats->execute(array(':id' => $id));
// Check if request is success
if ($resultats) {
echo "success";
}
// or if the request is failed
else {
echo "fail";
}
} catch(Exception $e) {
echo 'Erreur : '.$e->getMessage().'<br />';
echo 'N° : '.$e->getCode();
}
?>