mysql_stmt_affected_rows(3)
β¨ 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 bymysql_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
REPLACEstatement 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
- 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