Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Preparation of php environment and encapsulation of MySQL code

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report