pdo lastInsertId() returning 0

68 Views Asked by At

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 ?

0

There are 0 best solutions below