定义和用法
这个mysqli_get_charset()函数返回字符集类的对象,其中包含以下属性 -
charset:字符集的名称。
collation:归类的名称。
dir:字符集的目录。
min_length:最小字符长度(字节)。
max_length:最大字符长度(字节)。
number:字符集编号。
state:字符集状态。
用法
mysqli_get_charset($con)
参数
| Sr.No | 参数及说明 |
|---|---|
| 1 |
con(Mandatory) 这是一个表示与 MySQL 服务器的连接的对象。 |
返回值
mysqli_get_charset() 函数返回字符集类的对象。
PHP版本
这个函数最初是在 PHP 版本 5 中引入的,适用于所有后续版本。
示例
以下示例演示了 mysqli_get_charset() 函数的用法(程序风格) -
<?php
$db = mysqli_init();
//Creating the connection
mysqli_real_connect($db, "localhost","root","password","test");
//Character set
$res = mysqli_get_charset($db);
print_r($res);
?>
这将产生以下结果 -
stdClass Object
(
[charset] => utf8
[collation] => utf8_general_ci
[dir] =>
[min_length] => 1
[max_length] => 3
[number] => 33
[state] => 1
[comment] => UTF-8 Unicode
)
示例
在面向对象风格中,这个函数的语法是 $db->get_charset();以下是面向对象样式 $minus 中此函数的示例;
<?php
$db = mysqli_init();
//Connecting to the database
$db->real_connect("localhost","root","password","test");
//Name of the character set
$res = $db->get_charset();
print_r($res);
?>
这将产生以下结果 -
stdClass Object
(
[charset] => utf8
[collation] => utf8_general_ci
[dir] =>
[min_length] => 1
[max_length] => 3
[number] => 33
[state] => 1
[comment] => UTF-8 Unicode
)
示例
<?php
$connection_mysql = mysqli_connect("localhost","root","password","mydb");
if (mysqli_connect_errno($connection_mysql)){
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}
var_dump(mysqli_get_charset($connection_mysql));
mysqli_close($connection_mysql);
?>
这将产生以下结果 -
object(stdClass)#2 (8) {
["charset"]=>
string(4) "utf8"
["collation"]=>
string(15) "utf8_general_ci"
["dir"]=>
string(0) ""
["min_length"]=>
int(1)
["max_length"]=>
int(3)
["number"]=>
int(33)
["state"]=>
int(1)
["comment"]=>
string(13) "UTF-8 Unicode"
}
Default character set is:utf8
相关用法
- PHP mysqli_get_connection_stats()用法及代码示例
- PHP mysqli_get_client_version()用法及代码示例
- PHP mysqli_get_client_info()用法及代码示例
- PHP mysqli_get_client_stats()用法及代码示例
- PHP mysqli_get_server_info()用法及代码示例
- PHP mysqli_get_warnings()用法及代码示例
- PHP mysqli_get_host_info()用法及代码示例
- PHP mysqli_get_server_version()用法及代码示例
- PHP mysqli_get_proto_info()用法及代码示例
- PHP mysqli_data_seek()用法及代码示例
- PHP mysqli_insert_id()用法及代码示例
- PHP mysqli_fetch_assoc()用法及代码示例
- PHP mysqli_connect_error()用法及代码示例
- PHP mysqli_fetch_all()用法及代码示例
- PHP mysqli_next_result()用法及代码示例
- PHP mysqli_stmt_affected_rows()用法及代码示例
- PHP mysqli_begin_transaction()用法及代码示例
- PHP mysqli_real_escape_string()用法及代码示例
- PHP mysqli_fetch_lengths()用法及代码示例
- PHP mysqli_character_set_name()用法及代码示例
注:本文由纯净天空筛选整理自 PHP mysqli_get_charset() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
