Home > Database > Mysql Tutorial > How to Store and Retrieve Hindi Language Data in MySQL Using PHP?

How to Store and Retrieve Hindi Language Data in MySQL Using PHP?

DDD
Release: 2024-11-18 05:42:02
Original
947 people have browsed it

How to Store and Retrieve Hindi Language Data in MySQL Using PHP?

Storage of Unicode Data in Hindi Language in MySQL

In a PHP application utilizing MySQL, it's essential to know how to store and retrieve Hindi language data effectively. Let's delve into the process of storing data in MySQL in a readable Unicode format.

To store Hindi data in a readable format, the utf8 character set and utf8_general_ci collation should be employed. Ensure that the collation of the field designated for Hindi text storage is set to utf8_general_ci. To rectify any existing field, utilize the following code:

ALTER TABLE `<table_name>` CHANGE `<field_name>` `<field_name>` VARCHAR(100) 
CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT NULL;
Copy after login

Upon database connection, begin with this statement:

mysql_set_charset('utf8');
Copy after login

For instance:

// Character set configuration
mysql_set_charset('utf8');

// Insert Hindi text
mysql_query("INSERT INTO ....");
Copy after login

To retrieve Hindi data, the charset configuration should also be employed:

// Character set configuration
mysql_set_charset('utf8');

// Select Hindi text
mysql_query("SELECT * FROM ....");
Copy after login

Prior to displaying Unicode text (Hindi in this case) on a browser, it's imperative to specify the content type with a meta tag:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Copy after login

Code Example:




<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Example Unicode

Copy after login

Note:

The preferred method for changing the character set is mysql_set_charset('utf8'). Utilizing mysql_query() (e.g., SET NAMES utf8) is discouraged.

The above is the detailed content of How to Store and Retrieve Hindi Language Data in MySQL Using PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template