Database usage steps and coding problems

Source: Internet
Author: User
In the past two days, we have introduced the addition and deletion of simple message Books. when we use databases, we often encounter garbled characters, and encoding problems often plague us. So how can we solve this problem for new users? The following are some notes

In the past two days, we have introduced the addition and deletion of simple message Books. when we use databases, we often encounter garbled characters, and encoding problems often plague us. So how can we solve this problem for new users? The following are some points worth attention.

First, unify the encoding of PHP, HTML files, and databases. for example, if GBK is used, set it on the corresponding page:

1. HTML page encoding settings:

2. php file encoding settings: header ('content-Type: text/html; charset = gbk ')

3. database encoding settings: Select gbk_chinese_ci when creating a database.

4, HTML, PHP file class type stored as ANSI, if the unified use of UTF-8 encoding, then the file type is saved as a UTF-8, be sure not to BOM header

Pay attention to the following steps when using the database:

1. first establish database connection mysql_connect ('localhost', 'root', 'root ')

2. select the database mysql_select_db ('database _ name ')

3. write an SQL statement: $ SQL = ""; (add, delete, modify, query, or CURD)

4. execute the SQL statement $ res = mysql_query ($ SQL)

5. obtain the result mysql_fetch_assoc ($ res)

Note: mysql_query () executes the SQL statement, and mysql_fetch_assoc () executes the data of the resource type returned by mysql_query.

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.