定義和用法
這個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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
