PHP RFC: Add PDO function: mysqlGetWarningCount
- Version: 1.0
- Date: 2021-02-26
- Author: Daniel Beardsley, email@example.com
- Status: Under Discussion
Knowing if a query you ran generated warnings in your database is very important. MySQL warns about values getting truncated, inserting nulls into not-null columns and lots of other things. PDO currently makes discovering these warnings harder and more expensive than it needs to be. Right now, this requires running another query (
SHOW WARNINGS) after each query, incurring another round trip over the network to the database. It turns out that MySQL already provides the warning count in the meta-data of every result set, but PDO doesn't make it accessible.
Add a function that exposes the warning count of the most recent statement for MySQL:
$pdo->mysqlGetWarningCount(). It returns an
int straight from the MySQL driver. This fixes the open bug at: https://bugs.php.net/bug.php?id=51499.
I didn't look at every one, but most other SQL drivers don't seem to have a concept of “SHOW WARNINGS” and thus this feature (getting the warning count) only really applies to MySQL. Regarding maintenance, the MySQL function that this code wraps hasn't change in decades and isn't likely to change in the future, so maintenance should be low to nil.
Backward Incompatible Changes
Proposed PHP Version(s)
I made the pull-request against 7.4, but this is applicable to all php versions.
Proposed Voting Choices
“Yes” means this pull request should be merged (pending code review). “No” means we don't want PDO to expose MySQLs warning count.
Patches and Tests
There's an open pull with tests: https://github.com/php/php-src/pull/6677