mysql_stmt_affected_rows(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_affected_rows ✨

okay bestie, gather round, because this is the little function from MariaDB Connector/C that tells you how many rows actually got touched by your prepared statement πŸ’… it's called mysql_stmt_affected_rows, and ngl it's giving "main character of the DML world."


🌸 NAME 🌸

mysql_stmt_affected_rows β€” returns the number of affected rows from a previously executed prepared statement πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <mysql.h>

my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT * stmt);

πŸ’– DESCRIPTION πŸ’–

So basically, this function returns the number of affected rows produced by the last prepared statement associated with mysql β€” but only if that operation was an "upsert" situation, meaning an INSERT, UPDATE, DELETE or REPLACE statement. ✨

And if the last prepared statement failed? It gives you -1. 😭 not the vibe, but at least you know.


🫢 PARAMETER 🫢

  • stmt β€” a statement handle, which was previously allocated by mysql_stmt_init() 🌈

πŸ‘‘ NOTES πŸ‘‘

  • When you're using UPDATE, MariaDB will not update columns where the new value is the same as the old value. Which means... plot twist 😳 mysql_stmt_affected_rows() may not actually equal the number of rows matched β€” it's only the number of rows that were literally affected by the query. periodt.
  • The REPLACE statement is a whole two-step queen: it first deletes the record with the same primary key, and then inserts the new record. So this function returns the number of deleted records in addition to the number of inserted records. πŸ’€ two for one, fr fr.

πŸ”₯ SEE ALSO πŸ”₯


and that's the whole thing, bestie 🧚 this page was serving Version 3.4 energy, courtesy of the MariaDB Connector/C girlies β€” go forth and count your rows, no cap πŸ’œπŸŒΈπŸ¦‹

πŸ“¦ where this page comes from