Home Backend Development PHP Tutorial Why does my Mysql not support Chinese queries?_PHP tutorial

Why does my Mysql not support Chinese queries?_PHP tutorial

Jul 13, 2016 am 10:52 AM
mysql not support Chinese Why Write Include exist Field I hour condition Inquire of question

Q:
My problem when writing a query condition is as follows:
For example, I want to write all the records containing the word "李" in a field
$str="李";
select * from table where field like '%$str%' ;
In addition to the records containing the word "李", the displayed records also have records that do not contain the word "李". Why?

A:
In MySQL, when sorting and searching Chinese characters, the sorting and search results for Chinese characters are wrong. This situation exists in many versions of MySQL. If this problem is not solved, then MySQL will not be able to actually handle Chinese.
The reason for this problem is: MySQL is case-insensitive when querying strings. When compiling MySQL, the ISO-8859 character set is generally used as the default character set. Therefore, during the comparison process, the Chinese coded character size Write conversion causes this behavior.
Method 1:
The solution is to add the "binary" attribute to the field containing Chinese to make it a binary comparison, for example, change "name char(10)" to "name char(10)binary".
Method 2:
If you use source code to compile MySQL, you can use the --with--charset=gbk parameter when compiling MySQL, so that MySQL will directly support Chinese search and sorting.
Method 3:
You can use Mysql’s locate function to determine. Taking the above problem as an example, the usage method is:
SELECT * FROM table WHERE locate(field,'李') > 0;
This method is used on this site, and it feels pretty good. :P
Method 4:
Change your Select statement to this, SELECT * FROM TABLE WHERE FIELDS LIKE BINARY '%FIND%'!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632466.htmlTechArticleQ: The questions I have when writing a query condition are as follows: For example, I want to write a field that contains "李" All records of word $str="李"; select * from table where field like %$str%; Displayed records...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Free market software app website Free market software app website Mar 05, 2025 pm 09:03 PM

This article introduces free digital asset quotation software apps and websites that can provide investors with key information such as real-time prices, price charts, transaction volume, fluctuations, market depth and news information to help investors make informed decisions. Compared with paid software, free software has the advantages of no cost, rich features, and easy operation. The article also guides users how to choose the right market software, and reminds users to pay attention to data sources, information accuracy and avoid excessive dependence, which ultimately helps investors better grasp the trends of the digital asset market. Want to know how to use free market software efficiently? Read the full text quickly!

gateio exchange app old version gateio exchange app old version download channel gateio exchange app old version gateio exchange app old version download channel Mar 04, 2025 pm 11:36 PM

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.

Bitcoin: The 'barometer' of global liquidity? Bitcoin: The 'barometer' of global liquidity? Mar 04, 2025 pm 06:39 PM

The liquidity of the crypto market was tight, and Bitcoin fell again after continuing to fluctuate, hitting a low of $86,000, down nearly 20% from its peak. Bitcoin, the leader in cryptocurrency, has caused altcoins to collapse, and market sentiment has also shifted from fanaticism to panic. Is the Bitcoin bull market over? What is the future trend? These issues have attracted much attention. But Bitcoin trends are closely linked to global financial markets, and SwanBitcoin research analyst Sam Callahan's article on the relationship between Bitcoin price and global liquidity is worth reading. The core point of the article: Bitcoin price is consistent with global liquidity trends 83% of the time, which is higher than other major assets, making it an effective indicator for measuring liquidity conditions. Although Bitcoin is highly liquid in the world

BitMEX: Best option strategy after a big sell-off BitMEX: Best option strategy after a big sell-off Mar 04, 2025 pm 06:27 PM

Source: BitMEX Welcome to our weekly options Alpha series: Bitcoin has just dropped sharply, with a drop of 10%. Your portfolio is losing money and you may think, "What should you do next? Should you panic, increase your position, or do it smartly?" Options strategies can help manage risks, take advantage of possible rebounds, or generate revenue. Here are five effective strategies for post-selling scenarios, accompanied by examples, profit and loss analysis, and situational guidance. (As of this article was written, February 26, 2025, 13:06 Hong Kong time, the price of BTC was $88,584.) 1. If you are worried that Bitcoin will continue to decline in March... Practice: Buy protective put options (your insurance strategy) Assume you hold

How to download gateio mobile Android version How to download Gate.io mobile Android version How to download Gate.io mobile Android version How to download gateio mobile Android version How to download Gate.io mobile Android version How to download Gate.io mobile Android version Mar 04, 2025 pm 09:57 PM

The steps for downloading Gate.io Android mobile version are as follows: 1. Visit the official Gate.io website and download the APK file. 2. Enable installation options from unknown sources in the device. 3. Install the APK file and follow the prompts. 4. Complete the installation and start the application.

Finalbosu airdrop full solution: Participate, earn and join the whitelist Finalbosu airdrop full solution: Participate, earn and join the whitelist Mar 05, 2025 pm 01:09 PM

Finalbosu is a community-driven NFT project built on the abstract chain that combines amazing anime-style artwork with dynamic gameplay to immerse players in a rich, ever-evolving universe. Finalbosu's motto is "overcome all difficulties" and aims to seek to open up its own niche in the Web3 gaming and NFT ecosystem by allowing holders to shape the future of their characters, storylines and brand direction. The project has gained great appeal, with its original collection at a base price of 1.9 ETH – a testament to strong market demand and solid support from its growing community. Now, with Finalbo

Coinbase Exchange Login Port 2025 Coinbase Exchange Login Port 2025 Mar 21, 2025 pm 05:51 PM

Coinbase Security Login Guide: How to Avoid Phishing Sites and Scams? Phishing and scams are becoming increasingly rampant, and it is crucial to securely access the Coinbase official login portal. This article provides practical guides to help users securely find and use the latest official login portal of Coinbase to protect the security of digital assets. We will cover how to identify phishing sites, and how to log in securely through official websites, mobile apps or trusted third-party platforms, and provide suggestions for enhancing account security, such as using a strong password and enabling two-factor verification. To avoid asset losses due to incorrect login, be sure to read this article carefully!

What are the market software app websites that do not charge money What are the market software app websites that do not charge money Mar 05, 2025 pm 08:57 PM

This article provides a comprehensive guide to free digital asset market software to help you grasp the pulse of the market at no cost. In digital asset trading, timely and accurate market data is crucial, but expensive paid software has discouraged many novices. Fortunately, many free apps and websites provide real-time price tracking, historical data review, transaction volume monitoring and other functions to help you understand market dynamics and make informed decisions. The article will introduce the types, selection techniques and precautions of free market software in detail, allowing you to invest safely and efficiently in the extremely risky digital asset market.

See all articles