Expose five common database problems in PHP applications-including database pattern design, database access and use of database business logic code-and their solutions.
Expose five common database problems in PHP applications-including database pattern design, database access and use of database business logic code-and their solutions.
If there is only one way to use the database, it is correct ......
You can create database design, database access, and database-based PHP business logic code in many ways, but it generally ends with an error. This article describes the five common problems in the PHP code for database design and database access, and how to fix these problems.
Question 1: use MySQL directly
A common problem is that older PHP code directly uses the mysql _ function to access the database. Listing 1 shows how to directly access the database.
Reference content is as follows: Function get_user_id ($ name) { $ Db = mysql_connect ('localhost', 'root', 'password '); Mysql_select_db ('users '); $ Res = mysql_query ("SELECT id FROM users WHERE login = '". $ name ."'"); While ($ row = mysql_fetch_array ($ res) {$ id = $ row [0];} Return $ id; } Var_dump (get_user_id ('Jack ')); ?> |
Listing 1. Access/get. php