mysql_stmt_insert_id(3)
mysql_stmt_insert_id πβ¨
okay bestie, so we're in the MariaDB Connector/C manual, and today's main character is mysql_stmt_insert_id β she's the one who tells you what ID the database just made up for you. no cap.
β¨ NAME β¨
mysql_stmt_insert_id β returns the auto generated id from a previously executed prepared statement. she's giving "who am I" but for rows. π
πΈ SYNOPSIS πΈ
#include <mysql.h>
my_ulonglong mysql_stmt_insert_id(MYSQL_STMT * stmt);
π¦ DESCRIPTION π¦
so mysql_stmt_insert_id() hands you back the ID that was generated by a prepared statement, on a table that has a column with the AUTO_INCREMENT attribute. literally the "ooh what number did I get" function. π₯
Parameter
stmtβ a statement handle, which was previously allocated bymysql_stmt_init(3). don't just make one up out of thin air, she needs to already exist fr fr. π«Ά
Return value
returns the auto generated id from a previously executed prepared statement.
and here's the plot twist π β if the last query wasn't an INSERT or UPDATE statement, or if the modified table does not have a column with the AUTO_INCREMENT attribute, this function will return zero. so a zero is not "no thoughts head empty", it's "nothing got auto-generated, babe". π
π NOTES π
- when you're doing a multi insert prepared statement,
mysql_stmt_insert_id()will return the value of the first row. yes, just the first one. the rest are on their own. π
π SEE ALSO π
mysql_insert_id(3)
not me being obsessed with auto-increment IDs at this hour... but honestly? iconic. β
and that's the whole page, bestie β slay π this was the mysql_stmt_insert_id(3) page, part of the MariaDB Connector/C docs, Version 3.4. mwah, go insert something. πβ¨π¦
π¦ where this page comes from
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms