I haven't written a program for many years, and now I am unfamiliar with php + mysql database programming. Recently I have recovered again. Of course, I have encountered such a problem at the beginning.
Garbled Problem
According to previous habits, I wrote the following code;
$ Link = mysql_connect ('localhost', 'hgqy', 'hgqy'); // connect to the Data Server
Mysql_select_db ('hgqy', $ link); // select a database
$ SQL = "select * from 'plug _ qiye 'where cpname = 'jinan '";
$ Query = mysql_query ($ SQL) or die ("query failed". mysql_error (); // execute the data query statement
$ Row = mysql_fetch_array ($ query );
Foreach ($ row as $ I ){
Echo $ I;
}
The problem arises when the output is complete. I tested all the methods I know and did not find the cause. So I started to replace cpname = 'jinan 'with id =. The problem was finally found, and the output text was garbled. After checking the information, I found that after selecting the database, I had to perform another step.
Mysql_query ("set names utf8"); // sets the encoding. You can adjust utf8 and gbk by yourself.
This time the output is correct.