mysql_stmt_insert_id(3)

πŸ“¦
version 13.0.2 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

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 by mysql_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