S
S
sprashivatel2020-02-27 00:38:11
MySQL
sprashivatel, 2020-02-27 00:38:11

How to assign an inserted id during an INSERT query?

if (!isset($_SESSION['uid'])) {
    $this->pdo('insert into users set login = ?', [
        // сюда нужно вставить значение 'Пользователь-айди_под_которым_вставлена_строка'
    ]);
    $_SESSION['uid'] = $this->connection->lastInsertId(); // с этим как раз-таки всё понятно
}

Such is the question, that is, is it possible to do this without first determining the id_under_which_the_line_is_inserted?

Why, if asked: create a temporary account, which will then be filled with a normal login there with a password, soap with confirmation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-02-27
@nokimaro

Analogues lastInsertId() Get current auto increment value from information_schema or via TABLE STATUS
SELECT LAST_INSERT_ID();

SELECT AUTO_INCREMENT
FROM information_schema.tables
WHERE table_name = 'table_name'
AND table_schema = DATABASE( ) ;

SHOW TABLE STATUS LIKE 'table_name'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question