From c7915950382c9347fbaf2586a30a9d1010d2e297 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 6 Jul 2024 09:53:55 +0200 Subject: [PATCH 1/2] Add warning about using sql_affectedrows() --- development/db/dbal.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/development/db/dbal.rst b/development/db/dbal.rst index 55eb8be1..c4d62bf2 100644 --- a/development/db/dbal.rst +++ b/development/db/dbal.rst @@ -383,6 +383,13 @@ Example: $affected_rows = $db->sql_affectedrows(); +.. warning:: + Be cautious when using ``sql_affectedrows()`` to determine the number of rows affected by your query. + This function's behavior can differ depending on the used database driver and whether the query was cached. + + Do not rely solely on ``sql_affectedrows()`` to confirm the number of impacted rows. Consider alternative approaches + like checking the number of rows returned by `sql_fetchrow`_ or `sql_fetchrowset`_. + sql_nextid ---------- Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. From 3a3b8a7d88b2eaea824331ccac9798257be96be3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 6 Jul 2024 23:07:04 +0200 Subject: [PATCH 2/2] Highlight SELECT queries as cause of issues with sql_affectedrows --- development/db/dbal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/db/dbal.rst b/development/db/dbal.rst index c4d62bf2..34e7000d 100644 --- a/development/db/dbal.rst +++ b/development/db/dbal.rst @@ -384,7 +384,7 @@ Example: $affected_rows = $db->sql_affectedrows(); .. warning:: - Be cautious when using ``sql_affectedrows()`` to determine the number of rows affected by your query. + Be cautious when using ``sql_affectedrows()`` to determine the number of rows affected by your query, especially with **SELECT** queries. This function's behavior can differ depending on the used database driver and whether the query was cached. Do not rely solely on ``sql_affectedrows()`` to confirm the number of impacted rows. Consider alternative approaches