Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Preparation of php environment and encapsulation of MySQL code

Shulou Source: shulou.com Published: 2022-06-02 04:20:30 09月22日 Update

This article mainly explains "php environment preparation and MySQL code encapsulation". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "php environment preparation and MySQL code encapsulation".

1. Required environment

PHP + Linux (centos7.3) + MySQL+Nginx+phpstudy+Redis

two。 Code warehouse

Using git to manage code requires a version control even if it is developed by yourself.

3. Purpose of learning system

1. How to design and implement a second kill system

two。 Achieve high concurrency and high performance of the system

3. Realize the safety and reliability of the system

4. The code address is the directory structure of the MySQL encapsulated code

Git address: https://github.com/fangkang7/Seckill.git

Directory location

5. Detailed explanation of MySQL code encapsulation

Due to the problems shown, you can go to git and drop down the code, and then compare it with this. I'll just take a screenshot to illustrate it.

The first part is a part of the defined parameters. This time, the connection MySQL uses the connection of PDO. If you have not touched the connection method of pdo, then don't worry, it will infiltrate a little bit later.

2. GetInstance uses a singleton to create an instantiated connection object, and the constructor is only used to connect the data using the

3. Connect to the database

4. Initialization method of sql statement execution

Here we use the placeholder of pdo to concatenate SQL. In normal times, our sql statement will be select * from user where id = 1.

In pdo we can select * from user where id =? And username =?, array (1)

It can also be select * from user where id =: id and useraname:id, array ('id'= > 1 recording username' = > 'kaka')

In this way, the sql injection can be well placed.

5. Use placeholders to process parameters

6. Execute query method

7. Get the inserted id

8. The rest of the methods are not very important, so they are not explained. Later, they are used to say that this code is also referenced by others, so you still need to take a good look at it and learn other people's encapsulation code.

6. Curd package of MySQL

The code is also under MySQL\ class. This file is the encapsulation of some curd operations. Just pull it down and have a look.

Open the UC browser to see more wonderful pictures

Thank you for reading, the above is the content of "php environment preparation and MySQL code encapsulation". After the study of this article, I believe you have a deeper understanding of php environment preparation and MySQL code encapsulation, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Code encapsulation environment learning preparation system way method content parameter address data more directory statement problem important no that is warehouse Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker Linux Shulou Tech Info Huawei