note 73163 added to function.PDO-lastInsertId

From: Date: Sun, 11 Feb 2007 18:36:19 +0000
Subject: note 73163 added to function.PDO-lastInsertId
Groups: php.notes 
Request: Send a blank email to php-notes+get-123257@lists.php.net to get a copy of this message
This example shows you how to get the last inserted ID with the PDO extension and a MySQL database. <?php try { $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); $statement = $dbh->prepare('INSERT INTO foobar (foo, bar) VALUES(:foo, :bar)'); $statement->bindParam(':foo', 'Hello', PDO::PARAM_STR); $statement->bindParam(':bar', 'World', PDO::PARAM_STR); $statement->execute(); echo 'Insertion réussie !<br/>'; echo 'Dernier ID auto-incrémenté : ', $dbh->lastInsertId(); $statement = null; $dbh = null; } catch (PDOException $e) { echo 'Erreur ! : ', $e->getMessage() ,'<br/>'; } ?> ---- Server IP: 217.174.196.197 Probable Submitter: 84.100.90.92 ---- Manual Page -- http://www.php.net/manual/en/function.PDO-lastInsertId.php Edit -- https://master.php.net/note/edit/73163 Del: integrated -- https://master.php.net/note/delete/73163/integrated Del: useless -- https://master.php.net/note/delete/73163/useless Del: bad code -- https://master.php.net/note/delete/73163/bad+code Del: spam -- https://master.php.net/note/delete/73163/spam Del: non-english -- https://master.php.net/note/delete/73163/non-english Del: in docs -- https://master.php.net/note/delete/73163/in+docs Del: other reasons-- https://master.php.net/note/delete/73163 Reject -- https://master.php.net/note/reject/73163 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123257) next »