rfc:pdo-mysql-get-warning-count

PHP RFC: Add PDO function: mysqlGetWarningCount

  • Version: 1.0
  • Date: 2021-02-26
  • Author: Daniel Beardsley, dbeardsl@gmail.com
  • Status: Declined (Abandoned)

Introduction

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.

Proposal

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.

Caveat

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

None

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

Vote

Voting opened on 2021-07-06 and closes on 2021-07-21

Add PDO function: mysqlGetWarningCount
Real name Yes No
alec (alec)  
ashnazg (ashnazg)  
bmajdak (bmajdak)  
dharman (dharman)  
galvao (galvao)  
geekcom (geekcom)  
girgias (girgias)  
kalle (kalle)  
kguest (kguest)  
lcobucci (lcobucci)  
mbeccati (mbeccati)  
ocramius (ocramius)  
ramsey (ramsey)  
reywob (reywob)  
santiagolizardo (santiagolizardo)  
svpernova09 (svpernova09)  
zimt (zimt)  
Final result: 3 14
This poll has been closed.
rfc/pdo-mysql-get-warning-count.txt · Last modified: 2021/07/27 08:10 by salathe