# mysql\_stmt\_insert\_id

## Syntax

```c
my_ulonglong mysql_stmt_insert_id(MYSQL_STMT * stmt);
```

* `stmt` - a statement handle, which was previously allocated by [mysql\_stmt\_init()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_init).

## Description

The `mysql_stmt_insert_id()` function returns the ID generated by a prepared statement on a table with a column having the [AUTO\_INCREMENT](https://app.gitbook.com/s/SsmexDFPv2xG2OTyO5yV/reference/data-types/auto_increment) attribute. If the last query wasn't an [INSERT](https://app.gitbook.com/s/SsmexDFPv2xG2OTyO5yV/reference/sql-statements/data-manipulation/inserting-loading-data/insert) or [UPDATE](https://app.gitbook.com/s/SsmexDFPv2xG2OTyO5yV/reference/sql-statements/data-manipulation/changing-deleting-data/update) statement or if the modified table does not have a column with the `AUTO_INCREMENT` attribute, this function will return zero.

{% hint style="info" %}
When performing a multi-insert prepared statement, `mysql_stmt_insert_id()` will return the value of the first row.
{% endhint %}

## See Also

* [mysql\_insert\_id()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_insert_id)

{% @marketo/form formId="4316" %}
