mysql_affected_rows(3)
π mysql_affected_rows β the MariaDB Connector/C glow-up
okay bestie, welcome to the <mysql.h> cinematic universe β¨ this page is mysql_affected_rows(3) from the MariaDB Connector/C manual, and it's about to tell you how many rows your last query actually touched. yes, actually touched. we'll get to the drama.
πΈ Name
mysql_affected_rows β returns the number of rows affected by the last operation π
β¨ Synopsis
#include <mysql.h>
my_ulonglong mysql_affected_rows(MYSQL * mysql);
π¦ Description
So basically: this function hands you the number of affected rows from the last operation tied to mysql. It only counts if that operation was an "upsert" β and by that we mean an INSERT, UPDATE, DELETE or REPLACE statement. And if the last operation flopped? You get -1. not a vibe, but there it is π
Parameters:
mysqlβ a connection identifier. It's gotta be one you already allocated withmysql_init(3)and connected withmysql_real_connect(3). no sneaking in randoms, she needs to know her people π«Ά
Notes:
- When you're using
UPDATE, MariaDB will not update columns where the new value is the same as the old value. The way that this matters:mysql_affected_rowsmay not actually equal the number of rows matched β it's only the number of rows that were literally affected by the query. matched β affected, and she's counting affected. periodt π - The
REPLACEstatement 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, iconic behavior π
β Return value
Returns the number of affected rows, or -1 on error. that's it, that's the tea.
π See also
Version 3.4, MariaDB Connector/C β mwah, stay hydrated and always check your return values, bestie πβ¨ππ¦
π¦ 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