Пример #1
0
 $last_id = $row['_last_id'];
 if ($next_id != $last_id) {
     printf("[010] LAST_INSERT_ID() = %d and lastInserId() = %d differ\n", $last_id, $next_id);
 }
 $db->exec("INSERT INTO test(col1) VALUES ('c'), ('d'), ('e')");
 $next_id = (int) $db->lastInsertId();
 if ($next_id <= $last_id) {
     printf("[011] Expecting at least %d, got %d\n", $last_id + 1, $next_id);
 }
 // warnings are unhandy, lets go for exceptions for a second
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 try {
     $ignore_exception = true;
     $db->exec('LOCK TABLE test WRITE');
     $ignore_exception = false;
     if (MySQLPDOTest::getServerVersion($db) >= 50000) {
         $stmt = $db->query('SELECT @@auto_increment_increment AS inc');
         $row = $stmt->fetch(PDO::FETCH_ASSOC);
         $inc = $row['inc'];
     } else {
         $inc = 1;
     }
     $stmt = $db->query('SELECT LAST_INSERT_ID() as _last_id');
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $last_id = $row['_last_id'];
     $db->exec("INSERT INTO test(col1) VALUES ('z')");
     $next_id = (int) $db->lastInsertId();
     if ($next_id < $last_id + $inc) {
         printf("[012] Expecting at least %d, got %d\n", $last_id + $inc, $next_id);
     }
 } catch (PDOException $e) {