how to insert hindi text in mysql database using php? – TOP 3 BEST TIPS

how to insert hindi text in mysql database using php : In this article I will learn to store in to MySQL DB Hindi, Gujarati, Nepali, Telugu, Punjabi, Tamil, Marathi and Bengali etc. without losing its actual format or changing any content.

Easiest method : how to insert hindi text in mysql database using php?

In the first step to learn how to insert hindi text in mysql database using php?, I will make a database with the name of “Article Descriptions” and also make a database table with the name “Article”. simple answer for use to utf8 character set and utf8_general_ci collation.

The Database table will contain the 2 main columns id and name.

In the second step, I will insert the name in Hindi Languages format and then I will get the data from the mysql database and then we are showing it in the HTML nice table.

mysql_query(“SET CHARACTER SET utf8”) has changed/updated to mysql_set_charset(‘utf8’);

This is the preferred methods to update the charset. in this below example also learn to how to fetch and update data from database in php?

Create database:

CREATE DATABASE article_descriptions

          CHARACTER SET utf8

         COLLATE utf8_general_ci;

USE article_descriptions;

CREATE TABLE articles (

   'name' varchar(255) COLLATE utf8_general_ci NOT NULL

)

run the following statement at first

mysql_set_charset('utf8');

Index.php:






               how to insert hindi text in mysql database using php ?
               





Fetch.php:

In this Article getting this file, I will fetch the data from the mysql database and showing it in the HTML file.




               `



Articles Information

?>
Article NAME
hindi text in mysql database using php
hindi text in mysql database using php

For the developers struggling in storing and retrieving Unicode charsets of the languages, including languages like Hindi, Gujarati, Nepali, Tamil, Telugu, Punjabi, Marathi and Bengali etc.

how to store hindi text in mysql?

how to insert hindi text in mysql database
how to insert hindi text in mysql database
//To set the char set
mysql_set_charset('utf8');

//To select hindi data
mysql_query("SELECT * FROM your_table_name");

// To insert hindi data
mysql_query("INSERT INTO ....");

Aslo Imp Note: Before you showing the hindi Article content in your any types of the browser set content data type of that page using meta tag in header part like below.


1. Configure MySQL to support UTF-8

ALTER DATABASE YOUR_DATABASE_NAME
 CHARACTER SET = utf8mb4
 COLLATE = utf8mb4_unicode_ci;

Altering only table instead of entire database to support UTF-8:

ALTER TABLE YOUR_TABLE_NAME
 CONVERT TO CHARACTER SET utf8mb4
 COLLATE utf8mb4_unicode_ci;

Altering only specific column instead of entire table to support UTF-8:

ALTER TABLE
    YOUR_TABLE_NAME
    CHANGE COLUMN_NAME COLUMN_NAME
    VARCHAR(191)
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;

If you have online or local store phpMyAdmin installed, and the you can create these some changes using GUI based option by easy to use run this simple go to

phpMyAdmin –> Select Database –> Select Table –> Select operations.

2. PHP Script to Insert UTF-8 Unicode Charset to MySQL

Sample code: how to insert hindi text in mysql database using php?

connect_error) {
    die("Connection error: " . $conn->connect_error);
} 
$sql = "INSERT INTO TABLE_NAME(COLUMN_NAME)
VALUES ('हिंदी')";
if ($conn->query($sql) === TRUE) {
    echo "Good Luck Data has been inserted.";
} else {
    echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>

Also how to insert hindi text in mysql database using php? Doc : mysql_set_charset

Leave a Comment