[php-src] Issue #21338: metadata checks (chatsetnr) in various mysqli tests fail
[email protected] (9EOR9)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <QMGOB4TJaIQMAShEYMDD9KGDTuiYysZNLCMmVf97ix0@main.internal.php.net> |
Issue: https://github.com/php/php-src/issues/21338
Author: 9EOR9
### Description
The following test:
```sapi/cli/php -f run-tests.php ext/mysqli/tests/mysqli_fetch_field.phpt
```
Resulted in this output:
```========DIFF========
--
["decimals"]=>
int(0)
}
057+ [004] Expecting charset utf8/33 got 192
bool(false)
mysqli_result object is already closed
array(1) {
--
========DONE========
FAIL mysqli_fetch_field() [ext/mysqli/tests/mysqli_fetch_field.phpt]
=====================================================================
Number of tests : 1 1
Tests skipped : 0 ( 0.0%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 1 (100.0%) (100.0%)
Tests passed : 0 ( 0.0%) ( 0.0%)
---------------------------------------------------------------------
Time taken : 0.110 seconds
=====================================================================
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
mysqli_fetch_field() [ext/mysqli/tests/mysqli_fetch_field.phpt]
=====================================================================
```
mysqli_set_charset() selects a character set by name only.
However, in MySQL/MariaDB a character set can have multiple collations, and the actual collation used determines the internal character set number (charsetnr) returned in metadata.
Several tests in the ext/mysqli test suite assume that setting utf8mb3 results in charsetnr = 33 (which corresponds to utf8mb3_general_ci). This assumption is not valid when the server default collation differs.
As a result, multiple tests fail depending on server configuration.
**Possible workarounds (quick fix):**
- use %d in the expect section
- use SET NAMES utf8mb3 COLLATE 'utf8mb3_general_ci' if you want to explicitly test for this character set/collation.
**Long term solution:**
Implement session_tracking (CLIENT_SESSION_TRACK capability) and obtain the character set information from session tracking information part of OK packet (or if not changed from server greeting packet),
### PHP Version
```plain
PHP 8.3.6 (cli) (built: Jan 7 2026 08:40:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
```
### Operating System
_No response_