PHP mysqli_character_set_name() 函式



定義和用法

mysqli_character_set_name() 函式返回當前資料庫連線的預設字元集名稱。

語法

mysqli_character_set_name($con)

引數

序號 引數 & 說明
1

con(必填)

這是一個代表與 MySQL 伺服器連線的物件。

返回值

mysqli_character_set_name() 函式返回一個字串值,表示當前字元集的名稱。

PHP 版本

此函式首次引入於 PHP 5 版本,並在所有後續版本中均有效。

示例

以下示例演示了 mysqli_character_set_name() 函式(過程式風格)的用法:

//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Name of the character set
$res = mysqli_character_set_name($con);
print($res);
//Closing the connection
mysqli_close($con);
?>

這將產生以下結果:

utf8

示例

在面向物件風格中,此函式的語法為 $con->character_set_name(); 以下是此函式在面向物件風格中的示例:

<?php
   $con = new mysqli("localhost", "root", "password", "test");
   //Name of the character set
   $res = $con->character_set_name();
   print($res);
   //Closing the connection
   $con -> close();
?>

這將產生以下結果:

utf8

示例

<?php
  $connection = mysqli_connect("localhost","root","password","mydb");
   
   if (mysqli_connect_errno($connection)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   
   $charset = mysqli_character_set_name($connection);
   echo "Default character set is: " . $charset;
   
   mysqli_close($connection);
?>

這將產生以下結果:

Default character set is: utf8
php_function_reference.htm
廣告