Commit d5ecbe1d936 for php.net
commit d5ecbe1d93694497bd46483bdbb169f2ec8655b4
Author: Kamil Tekiela <tekiela246@gmail.com>
Date: Mon Aug 10 23:04:41 2026 +0100
mysqli: Deprecate mysqli_get_charset() (#23206)
diff --git a/ext/mysqli/mysqli.stub.php b/ext/mysqli/mysqli.stub.php
index cc6b8c57404..c995cf564a5 100644
--- a/ext/mysqli/mysqli.stub.php
+++ b/ext/mysqli/mysqli.stub.php
@@ -797,6 +797,7 @@ public function debug(string $options): true {}
* @tentative-return-type
* @alias mysqli_get_charset
*/
+ #[\Deprecated(since: '8.6', message: 'did you mean mysqli_character_set_name()?')]
public function get_charset(): ?object {}
/**
@@ -1463,6 +1464,7 @@ function mysqli_get_connection_stats(mysqli $mysql): array {}
function mysqli_get_client_stats(): array {}
/** @refcount 1 */
+#[\Deprecated(since: '8.6', message: 'did you mean mysqli_character_set_name()?')]
function mysqli_get_charset(mysqli $mysql): ?object {}
/** @refcount 1 */
diff --git a/ext/mysqli/mysqli_arginfo.h b/ext/mysqli/mysqli_arginfo.h
index 0121f36f3cf..1fd84063441 100644
Binary files a/ext/mysqli/mysqli_arginfo.h and b/ext/mysqli/mysqli_arginfo.h differ
diff --git a/ext/mysqli/tests/mysqli_change_user_set_names.phpt b/ext/mysqli/tests/mysqli_change_user_set_names.phpt
index bcf957942f5..978150c3cbc 100644
--- a/ext/mysqli/tests/mysqli_change_user_set_names.phpt
+++ b/ext/mysqli/tests/mysqli_change_user_set_names.phpt
@@ -125,11 +125,12 @@
if (!is_object($charset = mysqli_get_charset($link)))
printf("[013] Expecting object/std_class, got %s/%s\n", gettype($charset), $charset);
- if ($charset->charset != $defaults['charset_connection'])
+ if ($charset->charset != $defaults['charset_connection'] || $link->character_set_name() != $defaults['charset_connection'])
printf("[014] Expecting connection charset to be %s got %s\n",
$defaults['charset_connection'],
$charset->charset);
+ // Remove the following test when removing mysqli_get_charset() in PHP 9.0.0
if ($charset->collation != $defaults['collation_connection'])
printf("[015] Expecting collation to be %s got %s\n",
$defaults['collation_connection'],
@@ -138,5 +139,6 @@
mysqli_close($link);
print "done!";
?>
---EXPECT--
+--EXPECTF--
+Deprecated: Function mysqli_get_charset() is deprecated since 8.6, did you mean mysqli_character_set_name()? in %s on line %d
done!
diff --git a/ext/mysqli/tests/mysqli_fetch_field.phpt b/ext/mysqli/tests/mysqli_fetch_field.phpt
index e65de2308ab..7519e572bb5 100644
--- a/ext/mysqli/tests/mysqli_fetch_field.phpt
+++ b/ext/mysqli/tests/mysqli_fetch_field.phpt
@@ -15,9 +15,7 @@
// Make sure that client, connection and result charsets are all the
// same. Not sure whether this is strictly necessary.
if (!mysqli_set_charset($link, 'utf8'))
- printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
-
- $charsetInfo = mysqli_get_charset($link);
+ printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
diff --git a/ext/mysqli/tests/mysqli_fetch_field_oo.phpt b/ext/mysqli/tests/mysqli_fetch_field_oo.phpt
index 0f2a6c55841..ad8f0439568 100644
--- a/ext/mysqli/tests/mysqli_fetch_field_oo.phpt
+++ b/ext/mysqli/tests/mysqli_fetch_field_oo.phpt
@@ -15,9 +15,7 @@
// Make sure that client, connection and result charsets are all the
// same. Not sure whether this is strictly necessary.
if (!$mysqli->set_charset('utf8'))
- printf("[%d] %s\n", $mysqli->errno, $mysqli->errno);
-
- $charsetInfo = $mysqli->get_charset();
+ printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
diff --git a/ext/mysqli/tests/mysqli_fetch_fields.phpt b/ext/mysqli/tests/mysqli_fetch_fields.phpt
index 2257c4d9d06..18e2fc7fe9a 100644
--- a/ext/mysqli/tests/mysqli_fetch_fields.phpt
+++ b/ext/mysqli/tests/mysqli_fetch_fields.phpt
@@ -15,9 +15,7 @@
// Make sure that client, connection and result charsets are all the
// same. Not sure whether this is strictly necessary.
if (!mysqli_set_charset($link, 'utf8'))
- printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
-
- $charsetInfo = mysqli_get_charset($link);
+ printf("[%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
diff --git a/ext/mysqli/tests/mysqli_field_seek.phpt b/ext/mysqli/tests/mysqli_field_seek.phpt
index af52bf6c97f..f9fe55aaf76 100644
--- a/ext/mysqli/tests/mysqli_field_seek.phpt
+++ b/ext/mysqli/tests/mysqli_field_seek.phpt
@@ -61,8 +61,6 @@ function mysqli_field_seek_flags($flags) {
if (!mysqli_set_charset($link, 'utf8'))
printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
- $charsetInfo = mysqli_get_charset($link);
-
if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1", MYSQLI_USE_RESULT)) {
printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
@@ -80,9 +78,10 @@ function mysqli_field_seek_flags($flags) {
$field = mysqli_fetch_field($res);
var_dump($field);
/* label column, result set charset */
- if ($field->length != $charsetInfo->max_length) {
+ $charMaxLength = 3;
+ if ($field->length != $charMaxLength) {
printf("[005] Expecting length %d got %d\n",
- $charsetInfo->max_length, $field->max_length);
+ $charMaxLength, $field->max_length);
}
var_dump(mysqli_field_tell($res));
diff --git a/ext/mysqli/tests/mysqli_get_charset.phpt b/ext/mysqli/tests/mysqli_get_charset.phpt
index 2752084372a..4753823227d 100644
--- a/ext/mysqli/tests/mysqli_get_charset.phpt
+++ b/ext/mysqli/tests/mysqli_get_charset.phpt
@@ -72,6 +72,10 @@
!is_int($charset->state))
printf("[022] Expecting int/any, got %s/%s\n", gettype($charset->state), $charset->state);
+ $charsetOO = $link->get_charset();
+ if ($charsetOO != $charset)
+ printf("[023] Expecting object/%s, got %s/%s\n", gettype($charset), gettype($charsetOO), $charsetOO);
+
mysqli_close($link);
try {
@@ -82,6 +86,11 @@
print "done!";
?>
---EXPECT--
+--EXPECTF--
+Deprecated: Function mysqli_get_charset() is deprecated since 8.6, did you mean mysqli_character_set_name()? in %s on line %d
+
+Deprecated: Method mysqli::get_charset() is deprecated since 8.6, did you mean mysqli_character_set_name()? in %s on line %d
+
+Deprecated: Function mysqli_get_charset() is deprecated since 8.6, did you mean mysqli_character_set_name()? in %s on line %d
mysqli object is already closed
done!
diff --git a/ext/mysqli/tests/mysqli_stmt_execute_stored_proc.phpt b/ext/mysqli/tests/mysqli_stmt_execute_stored_proc.phpt
index 935e541b789..766b105dcb6 100644
--- a/ext/mysqli/tests/mysqli_stmt_execute_stored_proc.phpt
+++ b/ext/mysqli/tests/mysqli_stmt_execute_stored_proc.phpt
@@ -24,7 +24,8 @@
if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
printf("[009] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
- if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) {
+ // The test fails on MariaDB when the version string is too long, so keep it at least 50
+ if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(50)) BEGIN SELECT VERSION() INTO ver_param; END;')) {
/* no result set, one output parameter */
if (!$stmt = mysqli_prepare($link, 'CALL p(@version)'))
printf("[011] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -66,7 +67,7 @@
if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
printf("[019] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
- if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) {
+ if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(50)) BEGIN SELECT VERSION() INTO ver_param; END;')) {
// no result set, one output parameter
if (!$stmt = mysqli_prepare($link, 'CALL p(@version)'))
printf("[020] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
diff --git a/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt b/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt
index 600c8ae4799..4cf36a58591 100644
--- a/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt
+++ b/ext/mysqli/tests/mysqli_stmt_get_result_metadata_fetch_field.phpt
@@ -15,8 +15,6 @@
if (!mysqli_set_charset($link, 'utf8'))
printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
- $charsetInfo = mysqli_get_charset($link);
-
if (!($stmt = mysqli_stmt_init($link)) ||
!mysqli_stmt_prepare($stmt, "SELECT id, label, id + 1 as _id, concat(label, '_') ___label FROM test ORDER BY id ASC LIMIT 3") ||
!mysqli_stmt_execute($stmt))
@@ -42,9 +40,10 @@
Label column, result set charset.
All of the following columns are "too hot" - too server dependent
*/
- if ($field->length != $charsetInfo->max_length) {
+ $charMaxLength = 3;
+ if ($field->length != $charMaxLength) {
printf("[005] Expecting length %d got %d\n",
- $charsetInfo->max_length, $field->max_length);
+ $charMaxLength, $field->max_length);
}
}
}