4
4
4sadly2020-04-28 00:18:28
PHP
4sadly, 2020-04-28 00:18:28

How to get a column that has autoincrement?

After inserting a row into the table, you need to get the id, how to do it?

$questionmarks = array_fill(0, sizeof($properties), '?');
$stmt = self::$db->prepare('INSERT INTO `' . static::getTableName() . '` (' . implode(',', array_keys($properties)) . ') VALUES (' . implode(',', $questionmarks) . ')');
$stmt->execute(array_values($properties));

Here is the code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-04-28
@4sadly

https://www.php.net/manual/ru/pdo.lastinsertid.php
https://www.php.net/manual/ru/mysqli.insert-id.php
https://dev.mysql.com/ doc/refman/8.0/en/informatio...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question