Example 1 — Print the Connection Character Set
Connect and read the character set name. Sample output when connected to a demo database.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
echo mysqli_character_set_name($mysqli), PHP_EOL;
mysqli_close($mysqli); How It Works
- mysqli_connect() opens the demo connection.
- mysqli_character_set_name() reads the active charset.
- The sample server is configured for utf8mb4.
- Close the connection when finished.

