What are the difficulties in PHP development?
Difficulties encountered 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. Not filtering user input
It should be: Never trust user input. Use back-end PHP to verify and filter each input information, don't trust Java.
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 a SELECT query. Do not use * to return all fields in the table. This 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. Not backing up
It may not happen often, but database damage, hard disk failure, service shutdown, etc., will cause catastrophic damage to the data. So you must make sure to automatically back up your data or save a copy.
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of What are the difficulties in PHP development?. For more information, please follow other related articles on the PHP Chinese website!