Guest User

Untitled

a guest
Apr 15th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. try {
  3.     $host="localhost"; $dbname="login"; $user="xxx"; $pass="xxx";
  4.    $dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
  5.  
  6.     $stmt = $dbh->prepare("INSERT INTO test (name) VALUES(?)");
  7.  
  8.     try {
  9.         $dbh->beginTransaction();
  10.         $stmt->execute( array('fehshfjk'));
  11.         $dbh->commit();
  12.         print $dbh->lastInsertId();
  13.     } catch(PDOExecption $e) {
  14.         $dbh->rollback();
  15.         print "Error!: " . $e->getMessage() . "</br>";
  16.     }
  17. } catch( PDOExecption $e ) {
  18.     print "Error!: " . $e->getMessage() . "</br>";
  19. }
  20. ?>
Add Comment
Please, Sign In to add comment