php / php/php-src

metadata checks (charsetnr) in various mysqli tests fail

Open
#21,338 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: mysqli Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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.
PHP Version
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ext/mysqli/tests/mysqli_fetch_field.phpt and run the sapi/cli/php command shown against a server whose default collation differs. Search the related ext/mysqli tests for hard-coded charsetnr 33 expectations, then verify that the affected tests pass while either accepting the server-dependent value or explicitly selecting the intended collation.

Written by the indexing model from the issue text.

Assessment

Tech stack
mariadb, mysql, php
Domain
databases, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.