Linux programming: five common PHP database problems

Source: Internet
Author: User
Tags php database
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

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.