pdo lastinsertid()返回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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论