1

last_insert_id返回新插入的行。

Perl 5.18 一切正常。

从论坛我了解到,这可能是因为一些失去联系。但是在跟踪中看不到任何东西。

这是代码示例:

  $self->_dbx->query(q{DROP TABLE IF EXISTS user_tbl;});

  $self->_dbx->query(q{
    CREATE TABLE user_tbl(
      user_id INT NOT NULL AUTO_INCREMENT,
      user_name VARCHAR(100) NOT NULL,
      PRIMARY KEY ( user_id )
    );
  });

  $self->_dbx->query(q{
    INSERT INTO user_tbl 
              (user_name)
      VALUES  ('DUMMY1');
  });

  print Dumper $self->_dbx->last_insert_id(undef, undef, undef, "user_id" ) or warn "Warn: Can not get it?";

  print Dumper $self->_dbx->query(q{
    SELECT * FROM user_tbl
      WHERE user_name= 'DUMMY1';
  })->hash;

DBI_TRACE:

    <- ping= ( 1 ) [1 items] at Driver.pm line 28
    <- prepare('
    CREATE TABLE user_tbl(
      user_id INT NOT NULL AUTO_INCREMENT,
      user_name VARCHAR(100) NOT NULL,
      PRIMARY KEY ( user_id )
    );
  ')= ( DBI::st=HASH(0x70f4468) ) [1 items] at Simple.pm line 168
    <- execute= ( '0E0' ) [1 items] at Simple.pm line 187
    <- finish= ( 1 ) [1 items] at Simple.pm line 286
    <- FETCH('Active')= ( 1 ) [1 items] at Connector.pm line 129
    <- FETCH('Active')= ( 1 ) [1 items] at Connector.pm line 129
    <- ping= ( 1 ) [1 items] at Driver.pm line 28
    <- prepare('
    INSERT INTO user_tbl 
              (user_name)
      VALUES  ('DUMMY1');
  ')= ( DBI::st=HASH(0x70f47c8) ) [1 items] at Simple.pm line 168
    <- execute= ( 1 ) [1 items] at Simple.pm line 187
    <- finish= ( 1 ) [1 items] at Simple.pm line 286
    <- FETCH('Active')= ( 1 ) [1 items] at Connector.pm line 129
    <- FETCH('Active')= ( 1 ) [1 items] at Connector.pm line 129
    <- ping= ( 1 ) [1 items] at Driver.pm line 28
    <- last_insert_id(undef, undef, ...)= ( '0' ) [1 items] at Simple.pm line 216

标准输出:

$VAR1 = '0';
$VAR1 = {
          'user_id' => 1,
          'user_name' => 'DUMMY1'
        };

版本:

  • Perl => 5.22
  • DBD::mysql => 4.043
  • MySQL 服务器 5.6
4

0 回答 0