mysqli_get_charset()函數(shù)返回字符集對(duì)象
mysqli_get_charset()函數(shù)返回字符集類的對(duì)象,其中包含以下屬性:
charset: 字符集的名稱。
collation: 排序規(guī)則的名稱。
dir: 被獲取的目錄字符集或者 ""。
min_length: 最小字符長度(字節(jié))。
max_length: 最大字符長度(字節(jié))。
number: 內(nèi)部字符集數(shù)。
state: 字符集狀態(tài)。
mysqli_get_charset($con)
| 序號(hào) | 參數(shù)及說明 |
|---|---|
| 1 | con(必需) 這是一個(gè)表示與MySQL Server的連接的對(duì)象。 |
mysqli_get_charset()函數(shù)返回的字符集的類的對(duì)象。
此函數(shù)最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
以下示例演示了mysqli_get_charset()函數(shù)的用法(面向過程風(fēng)格)-
<?php $db = mysqli_init(); //建立連接 mysqli_real_connect($db, "localhost","root","password","test"); //字符集 $res = mysqli_get_charset($db); print_r($res); ?>
輸出結(jié)果
stdClass Object ( [charset] => utf8 [collation] => utf8_general_ci [dir] => [min_length] => 1 [max_length] => 3 [number] => 33 [state] => 1 [comment] => UTF-8 Unicode )
在面向?qū)ο蟮臉邮街校撕瘮?shù)的語法為$db->get_charset();。以下是面向?qū)ο髽邮街写撕瘮?shù)的示例;
<?php
$db = mysqli_init();
//連接到數(shù)據(jù)庫
$db->real_connect("localhost","root","password","test");
//字符集名稱
$res = $db->get_charset();
print_r($res);
?>輸出結(jié)果
stdClass Object ( [charset] => utf8 [collation] => utf8_general_ci [dir] => [min_length] => 1 [max_length] => 3 [number] => 33 [state] => 1 [comment] => UTF-8 Unicode )
返回帶有屬性的字符集對(duì)象以及默認(rèn)的字符集:
<?php
$connection_mysql = mysqli_connect("localhost","root","password","mydb");
if (mysqli_connect_errno($connection_mysql)){
echo "連接MySQL失敗: " . mysqli_connect_error();
}
var_dump(mysqli_get_charset($connection_mysql));
mysqli_close($connection_mysql);
?>輸出結(jié)果
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