Home>Article>Backend Development> Summary of common problems in PHP development

Summary of common problems in PHP development

angryTom
angryTom Original
2019-07-16 11:37:43 3790browse

PHP is a server-side scripting language that is easy to learn and use. The syntax absorbs the characteristics of C language, Java and Perl, which is easy to learn and widely used. It is mainly suitable for the field of Web development. PHP's unique syntax mixes C, Java, Perl, and PHP's own syntax. It can execute dynamic web pages faster than CGI or Perl. Compared with other programming languages, dynamic pages made with PHP embed programs into HTML (an application under the Standard Universal Markup Language) document for execution, and the execution efficiency is much higher than CGI that completely generates HTML tags; PHP can also execute compiled code. Compilation can achieve encryption and optimize code running, making the code run faster.

Many programmers who are learning PHP now often encounter many problems during the development process. Here we have summarized the 10 most common problems in the PHP development process for you. We hope to help everyone during the development process. can help.

Summary of common problems in PHP development

1. Use MyISAM instead of InnoDB

MyISAM is used by default. But unless you are building a very simple database or just doing it experimentally, most of the time this is the wrong choice. MyISAM does not support foreign key constraints, which is the essence of ensuring data integrity. In addition, MyISAM will lock the entire table when adding or updating data, which will cause big problems in future expansion performance.

2. Use PHP’s mysql method

PHP has provided the MySQL function library from the beginning. Many programs rely on mysql_connect, mysql_query, mysql_fetch_assoc, etc.

3. Do not filter user input

It should be: Never trust user input. Use back-end PHP to verify and filter each input information. Don't trust Javascript.

4. Do not use UTF-8

UTF-8 solves many internationalization problems. Although PHP6 can solve this problem more perfectly, it does not prevent you from setting the character set of MySQL to UTF-8.

5. Use PHP where SQL should be used

If you are new to MySQL, sometimes when solving problems, you may first consider using a language you are familiar with. . This may cause some waste and poor performance. For example: when calculating the average, the MySQL native AVG() method is not used. Instead, PHP is used to loop through all the values and then accumulate them to calculate the average.

6. Not optimizing queries

99% of PHP performance problems are caused by the database. A bad SQL statement may make your entire program very slow. MySQL's EXPLAIN statement, Query Profiler, and many other tools can help you find those naughty SELECTs.

7. Using the wrong data type

MySQL provides a series of data types such as numbers, strings, time, etc. If you want to store dates, use the DATE or DATETIME type. Using integers or strings makes things more complicated.

8. Use *

in the SELECT query. Do not use * to return all fields in the table, which will be very slow. You only need to take out the data fields you need. If you need to remove all fields, then maybe your table needs to be changed.

9. Under-indexing or over-indexing

Generally speaking, all fields that appear after WHERE in the SELECT statement should be indexed.

10. No backup

It may not happen often, but the database is damaged, the hard disk is broken, the service is stopped, etc., these will cause catastrophic damage to the data. So you must make sure to automatically back up your data or save a copy.

If you want to know more about php, you can check out the interesting and useful knowledge in each part in thephp moduleof the website.

The above is the detailed content of Summary of common problems in PHP development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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