pdo lastinsertid()返回0

发布于 2025-01-26 20:59:59 字数 1311 浏览 4 评论 0原文

我的pdo last Insert ID返回0这是代码

  $bdd->beginTransaction();
$requete = $bdd->prepare('INSERT INTO reservation (code_salle,date_res,code_cr,code_profe)
 VALUE (:code_salle,:date_res,:code_cr,:code_profe)');
             $requete->execute(array(
                 'code_salle'=>$Salle,
                 'date_res'=>$date,
                 'code_cr'=>$heure,
                 'code_profe'=>$prof,   
             ));
            
  $last_id = $bdd->lastInsertId();
  echo "New record created successfully. Last inserted ID is: " .$last_id;


  $bdd->commit();

,这是我

try
{
     $bdd = new PDO('mysql:host=localhost;dbname=ebooking;charset=utf8', 'root', '');
     $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
} 

尝试

 $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

的连接,也无法正常

var_dump($bdd->lastInsertId());

工作 我得到的只是 c:\ wamp64 \ www \ e-e-booking \ try.php:76:字符串'0'(长度= 1)

成功创建了新的记录。最后插入的ID是:0

在数据库中,这是” ID Primaire auto_increment” 我认为我已经尝试了在stackoverflow上可以找到的所有解决方案,但没有任何工作 我在做什么错?

my pdo last insert id returns 0 here is the code

  $bdd->beginTransaction();
$requete = $bdd->prepare('INSERT INTO reservation (code_salle,date_res,code_cr,code_profe)
 VALUE (:code_salle,:date_res,:code_cr,:code_profe)');
             $requete->execute(array(
                 'code_salle'=>$Salle,
                 'date_res'=>$date,
                 'code_cr'=>$heure,
                 'code_profe'=>$prof,   
             ));
            
  $last_id = $bdd->lastInsertId();
  echo "New record created successfully. Last inserted ID is: " .$last_id;


  $bdd->commit();

and here is my connexion

try
{
     $bdd = new PDO('mysql:host=localhost;dbname=ebooking;charset=utf8', 'root', '');
     $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     
}
catch(Exception $e)
{
        die('Erreur : '.$e->getMessage());
} 

tried with the

 $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

ALSO didn't work and also the

var_dump($bdd->lastInsertId());

didn't work
ALL I'M GETTING IS
C:\wamp64\www\E-booking\try.php:76:string '0' (length=1)

or

New record created successfully. Last inserted ID is: 0

in the data base it's an"
Id Primaire AUTO_INCREMENT"
i think i've tried every solution i can find here on stackoverflow and yet nothing is working
what am I doing wrong ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文