Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What problems will php development encounter?
What problems will php development encounter?
What problems will php development encounter?

Inventory of ten 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 experimental, then most of the time this choice is wrong. MyISAM does not support foreign key constraints, which is the essence of ensuring data integrity. In addition, MyISAM will lock the whole table when adding or updating data, which will have great problems in future expansion performance.

2. Use mysql method of PHP.

PHP provided MySQL's function library from the beginning. Many programs rely on mysql_connect, mysql_query, mysql_fetch_assoc and so on.

3. User input is not filtered.

Never trust the user's input. Filter every input message with back-end PHP verification, and don't trust Javascript.

4. Don't use UTF-8

UTF-8 has solved many internationalization problems. Although PHP6 can solve this problem perfectly, it does not prevent you from setting MySQL's character set to UTF-8.

5. Use PHP where SQL should be used.

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

What are the difficulties in php development _ inventory of ten common problems in PHP development

6. Don't optimize the query

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

7. Using the wrong data type

MySQL provides a series of data types such as numbers, strings and time. If you want to store dates, using date or date-time type, using plastic or string will make things more complicated.

8. Use * in select queries

Don't use * to return all fields in the table, it will be very slow. You just need to take out the data fields you need. If you need to take out all the fields, then maybe your table needs to be changed.

9. Insufficient or excessive indexes.

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

10, no backup

It may not happen often, but the database is damaged, the hard disk is broken, and the service stops. This will cause catastrophic damage to the data. Therefore, you must ensure that data is automatically backed up or a copy is saved.

For more information about PHP, please visit PHP Chinese website!