I do not understand why these lines do not work:
$host = 'localhost';
$dbname='mydbname';
$login='mylogin';
$pwd='mypwd';
$datex = date('Y/m/d H:i:s');
$nomx = 'jrmy';
$numx = '007';
try {
$bdd = new PDO('mysql:host='.$host.';dbname='.$dbname, $login, $pwd);
}
catch(Exception $e) {
die('Erreur : '.$e->getMessage());
}
$bdd->exec('INSERT INTO dossiers(date, nom, numero, disp) VALUES(\''.$datex.'\', \''.$nomx.'\', \''.$numx.'\', \'Y\')');
$id = $bdd->lastInsertId();
$bdd= null;
echo 'id: '.$id;
disclosure: the script worked on my apache server, and since I installed my script on a IIS server it stopped working…
AND the query function works perfectly… query OK, insert NO
EDIT : thank you all! really!
You need to tell PDO to raise an error
Please note that the way you’re handling exceptions is quite useless. It would be better to remove try-catch blocks from the code