<?php
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "sakila");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
foreach (array('latin1', 'utf8') as $charset) {
// Set character set, to show its impact on some values (e.g., length in bytes)
mysqli_set_charset($link, $charset);
$query = "SELECT actor_id, last_name from actor ORDER BY actor_id";
echo "======================\n";
echo "Character Set: $charset\n";
echo "======================\n";
if ($result = mysqli_query($link, $query)) {
/* Get field information for all columns */
$finfo = mysqli_fetch_fields($result);
foreach ($finfo as $val) {
printf("Name: %s\n", $val->name);
printf("Table: %s\n", $val->table);
printf("Max. Len: %d\n", $val->max_length);
printf("Length: %d\n", $val->length);
printf("charsetnr: %d\n", $val->charsetnr);
printf("Flags: %d\n", $val->flags);
printf("Type: %d\n\n", $val->type);
}
mysqli_free_result($result);
}
}
mysqli_close($link);
?>
Exemplele de mai sus vor afișa:
======================
Character Set: latin1
======================
Name: actor_id
Table: actor
Max. Len: 3
Length: 5
charsetnr: 63
Flags: 49699
Type: 2
Name: last_name
Table: actor
Max. Len: 12
Length: 45
charsetnr: 8
Flags: 20489
Type: 253
======================
Character Set: utf8
======================
Name: actor_id
Table: actor
Max. Len: 3
Length: 5
charsetnr: 63
Flags: 49699
Type: 2
Name: last_name
Table: actor
Max. Len: 12
Length: 135
charsetnr: 33
Flags: 20489