note 129574 added to mysqli.info
| From: | Rumour | Date: | Mon, 10 Jun 2024 14:12:44 +0000 |
| Subject: | note 129574 added to mysqli.info | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221372@lists.php.net to get a copy of this message | ||
I don't recall where I got this, but it is SUPER important information and I cannot believe it
is missing from the documentation!
If you do a mysqli_info()/$mysqli->info() after a "INSERT INTO ... VALUES ()" that
adds/updates JUST ONE ROW, then, mysqli::info() returns an empty result (!!!).
If it is empty (null on php 8+; in php 7 I don't know in which way it is empty) check
$mysqli->affectedRows() or mysqli_affected_rows(). If that returns 2, the INSERT did a successful
UPDATE of ONE record (so there must have been a ON DUPLICATE KEY UPDATE). If it returns 1: there was
an INSERT of ONE record.
This is not a bug, this is BY DESIGN, although it does remind me strongly of "This is not a
bug, this is a feature" Microsoft of the 90's. I have no clue why you would design it this
way except for some weird and extremely old backward compatibility issues.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2a01:e0a:a51:3460:ec6e:e780:3c9a:b9a)
----
Manual Page -- https://php.net/manual/en/mysqli.info.php
Edit -- https://main.php.net/note/edit/129574
Del: integrated -- https://main.php.net/note/delete/129574/integrated
Del: useless -- https://main.php.net/note/delete/129574/useless
Del: bad code -- https://main.php.net/note/delete/129574/bad+code
Del: spam -- https://main.php.net/note/delete/129574/spam
Del: non-english -- https://main.php.net/note/delete/129574/non-english
Del: in docs -- https://main.php.net/note/delete/129574/in+docs
Del: other reasons-- https://main.php.net/note/delete/129574
Reject -- https://main.php.net/note/reject/129574
Search -- https://main.php.net/manage/user-notes.php