English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
mysqli_get_charset()関数が文字セットオブジェクトを返します
mysqli_get_charset()関数が返す文字セットのクラスのオブジェクトには以下の属性が含まれます:
charset: 文字セットの名前
collation: ソートルールの名前
dir: 取得されたディレクトリの文字セットまたは ""
min_length: 最小文字長さ(バイト)
max_length: 最大文字長さ(バイト)
number: 内部文字セット数
state: 文字セットの状態
mysqli_get_charset($con)
番号 | 引数および説明 |
---|---|
1 | con(必須) これはMySQL Serverとの接続を表すオブジェクトです。 |
mysqli_get_charset()関数が返す文字セットのクラスのオブジェクトです。
この関数は最初にPHPバージョン5で導入され、すべてのより高いバージョンで使用できます。
以下の例では、以下のように使用されます。mysqli_get_charset()関数の使い方(プロセス指向スタイル)-
<?php $db = mysqli_init(); //接続の確立 mysqli_real_connect($db, "localhost","root","password","test"); //文字セット $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();。以下は、オブジェクト指向スタイルでこの関数を使用する例です;
<?php $db = mysqli_init(); //データベースに接続 $db->real_connect("localhost","root","password","test"); //文字セット名 $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 "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" } デフォルトの文字セットは: utf8