php pdo查询问题

时间:2018-01-19 16:00:49

标签: php pdo

你好我的php查询需要一些帮助

php code =>

try
{
  $db = new PDO('mysql:host=localhost;dbname=monprojet;charset=UTF8', 'root', 'root');
}
catch(Exception $e)
{
  die('Erreur : '.$e->getMessage());
}
$login = $_POST['loginProfil'];

$mdp = $_POST['mdpProfil'];

$email = $_POST['emailProfil'];
try {
  $rep = $db->prepare('SELECT id FROM utilisateur WHERE login= :logi');
  $rep->execute(array(
    ':logi' => $_SESSION['login']
  ));
  $repo = $rep->fetch();
} catch (Exception $e) {
  die('Erreur de requete 1 : '.$e->getMessage());
}
try {
  $reponse = $db->prepare('UPDATE utilisateur SET login= :login, mdp= :mdp, email= :email WHERE id= :id');
  $reponse->execute(array(
    ':login' => $login,
    ':mdp' => $mdp,
    ':email' => $email,
    ':id' => $repo['id']
  ));
} catch (Exception $e) {
  die('Erreur de requete : '.$e->getMessage());
}
$json = json_encode($reponse->fetchAll());
$reponse->closeCursor();
echo $json;

我无法更新我的数据库,我不明白为什么,需要你的帮助Stack

1 个答案:

答案 0 :(得分:0)

如果表格未使用已发布的查询进行更新,请尝试检查更新查询id value中的WHERE clause

// Check if any data is found
$check = $db->prepare('SELECT COUNT(id) FROM utilisateur WHERE id= :id');

$check->execute(array(
    'id' => $repo['id']
));

var_dump( $check->fetchColumn() );

如果没有结果返回,那么您知道$ repo [' id']不在桌面上。