J
J
jfjd2021-02-02 23:25:15
PHP
jfjd, 2021-02-02 23:25:15

I can't display the last value of the id column, what's wrong?

Help to display the last value of the id column here is the code but it does not work thanks in advance

$result = $db->lastInsertRowid('id');

  foreach($result as $row) {

    print $row['id'];
  
    # code...
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-02-02
@rozhnev

In the case of SQLite, the lastInsertId function immediately returns a number:

$query = "insert into tbl (name) values (?);";
$stmt = $pdo->prepare($query);
$stmt->execute(['jfjd']);

print 'lastInsertId: ' . $pdo->lastInsertId();

Share PHP code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question