Php + mysql database programming learning details

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.