Php mysql get charset

PHP mysqli get_charset() Function

Return a character set object, with several properties:

$mysqli = new mysqli(«localhost»,»my_user»,»my_password»,»my_db»);

if ($mysqli -> connect_errno) echo «Failed to connect to MySQL: » . $mysqli -> connect_error;
exit();
>

Look at example of procedural style at the bottom.

Definition and Usage

The get_charset() / mysqli_get_charset() function returns a character set object with several properties for the current character set.

Syntax

Object oriented style:

Procedural style:

Parameter Values

Technical Details

  • charset — character set name
  • collation — collation name
  • dir — directory the charset was fetched from or «»
  • min_length — min character length in bytes
  • max_length — max character length in bytes
  • number — internal character set number
  • state — character set status

Example — Procedural style

Return a character set object, with several properties:

if (mysqli_connect_errno()) echo «Failed to connect to MySQL: » . mysqli_connect_error();
exit();
>

COLOR PICKER

HOW TO

SHARE

CERTIFICATES

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials

Top References

Top Examples

Web Certificates

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2020 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.

Читайте также:  Как запустить script python

Источник

mysqli_get_charset

Возвращает объект набора символов, предоставляющий несколько свойств текущего активного набора символов.

Список параметров

Только для процедурного стиля: Идентификатор соединения, полученный с помощью mysqli_connect() или mysqli_init()

Возвращаемые значения

Функция возвращает объект с следующими свойствами: charset

Директория, из которой получено описание набора символов. (?) или «» для встроенных наборов

Минимальная длина символа в байтах

Максимальная длина символа в байтах

Состояние набора символов (?)

Примеры

Пример #1 Пример использования mysqli::get_charset()

$db = mysqli_init ();
$db -> real_connect ( «localhost» , «root» , «» , «test» );
var_dump ( $db -> get_charset ());
?>

$db = mysqli_init ();
mysqli_real_connect ( $db , «localhost» , «root» , «» , «test» );
var_dump ( $db -> get_charset ());
?>

Результат выполнения данных примеров:

object(stdClass)#2 (7) < ["charset"]=>string(6) "latin1" ["collation"]=> string(17) "latin1_swedish_ci" ["dir"]=> string(0) "" ["min_length"]=> int(1) ["max_length"]=> int(1) ["number"]=> int(8) ["state"]=> int(801) >

Смотрите также

  • mysqli_character_set_name() — Возвращает кодировку по умолчанию, установленную для соединения с БД
  • mysqli_set_charset() — Задает набор символов по умолчанию

Источник

Get_charset

In this article, we will focus on the mysqli_get_charset() function in PHP, which is used to return the character set for the database connection. We will provide you with an overview of the function, how it works, and examples of its use.

Introduction to the mysqli_get_charset() function

The mysqli_get_charset() function is a built-in function in PHP that is used to return the character set for the database connection. This function is useful when you need to know the character set of a database connection.

How to use the mysqli_get_charset() function

Using the mysqli_get_charset() function is very simple. You just need to call the function on a valid MySQLi connection. Here is an example:

 $mysqli = mysqli_connect("localhost", "username", "password", "database"); $charset = mysqli_get_charset($mysqli); printf("Character set: %s\n", $charset->charset); mysqli_close($mysqli); ?>

In this example, we call the mysqli_connect() function to connect to a MySQL database with a username and password. We then call the mysqli_get_charset() function on the MySQLi connection to get the character set for the database connection. We then output the character set using the printf() function.

Conclusion

In conclusion, the mysqli_get_charset() function is a useful tool for returning the character set for the database connection. By understanding how to use the function, you can take advantage of this feature to create powerful and flexible MySQLi queries.

Источник

PHP mysqli: get_charset() function

mysqli_get_charset() function / mysqli::get_charset

The mysqli_get_charset() function / mysqli::get_charset returns a character set object.

Object oriented style

object mysqli::get_charset ( void )

Procedural style

object mysqli_get_charset ( mysqli $link )
Name Description Required/Optional
link A link identifier returned by mysqli_connect() or mysqli_init() Required for procedural style only and Optional for Object oriented style

Usage: Procedural style

mysqli_get_charset(connection);

Return value:

The function returns a character set object with the following properties:

Name Description
charset Character set name
collation Collation name
dir Directory the charset description was fetched from (?) or «» for built-in character sets
min_length Minimum character length in bytes
max_length Maximum character length in bytes
number Internal character set number
state Character set status (?)

Version: PHP 5, PHP 7

Example of object oriented style:

real_connect("localhost","user1","datasoft123","hr"); var_dump($db->get_charset()); ?> 
object(stdClass)#3 (8) < ["charset"]=>string(6) "latin1" ["collation"]=> string(17) "latin1_swedish_ci" ["dir"]=> string(0) "" ["min_length"]=> int(1) ["max_length"]=> int(1) ["number"]=> int(8) ["state"]=> int(1) ["comment"]=> string(0) "" >

Example of procedural style:

object(stdClass)#3 (8) < ["charset"]=>string(6) "latin1" ["collation"]=> string(17) "latin1_swedish_ci" ["dir"]=> string(0) "" ["min_length"]=> int(1) ["max_length"]=> int(1) ["number"]=> int(8) ["state"]=> int(1) ["comment"]=> string(0) "" >
 var_dump(mysqli_get_charset($con)); mysqli_close($con); ?> 
object(stdClass)#2 (8) < ["charset"]=>string(6) "latin1" ["collation"]=> string(17) "latin1_swedish_ci" ["dir"]=> string(0) "" 
["min_length"]=> int(1) ["max_length"]=> int(1) ["number"]=> int(8) ["state"]=> int(1) ["comment"]=> string(0) "" >

Previous: field_count
Next: get_client_info

Follow us on Facebook and Twitter for latest update.

PHP: Tips of the Day

How do I use PHP to get the current year?

You can use either date or strftime.

On a side note, when formatting dates in PHP it matters when you want to format your date in a different locale than your default. If so, you have to use setlocale and strftime. According to the php manual on date:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

  • Weekly Trends
  • Java Basic Programming Exercises
  • SQL Subqueries
  • Adventureworks Database Exercises
  • C# Sharp Basic Exercises
  • SQL COUNT() with distinct
  • JavaScript String Exercises
  • JavaScript HTML Form Validation
  • Java Collection Exercises
  • SQL COUNT() function
  • SQL Inner Join
  • JavaScript functions Exercises
  • Python Tutorial
  • Python Array Exercises
  • SQL Cross Join
  • C# Sharp Array Exercises

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook

Источник

PHP mysqli_get_charset() Function

This is an object representing a connection to MySQL Server.

Return Values

The mysqli_get_charset() function returns an object of the character set class.

PHP Version

This function was first introduced in PHP Version 5 and works works in all the later versions.

Example

Following example demonstrates the usage of the mysqli_get_charset() function (in procedural style) −

This will produce following result −

stdClass Object ( [charset] => utf8 [collation] => utf8_general_ci [dir] => [min_length] => 1 [max_length] => 3 [number] => 33 [state] => 1 [comment] => UTF-8 Unicode )

Example

In object oriented style the syntax of this function is $db->get_charset(); Following is the example of this function in object oriented style $minus;

real_connect("localhost","root","password","test"); //Name of the character set $res = $db->get_charset(); print_r($res); ?>

This will produce following result −

stdClass Object ( [charset] => utf8 [collation] => utf8_general_ci [dir] => [min_length] => 1 [max_length] => 3 [number] => 33 [state] => 1 [comment] => UTF-8 Unicode )

Example

 var_dump(mysqli_get_charset($connection_mysql)); mysqli_close($connection_mysql); ?>

This will produce following result −

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

Источник

Оцените статью