Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use PHP to operate database class

Shulou Source: shulou.com Published: 2022-05-31 21:43:26 09月16日 Update

This article mainly shows you "how to use PHP for database operation class", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use PHP for database operation class" this article.

PHP Advanced practice-Database Operation Class

Mainstream php development framework

Parent class (Mode1 class)

1. Review of sql statements

Insert into user (name, age, money) values ('abc', 18, 1000); update user set age=20, money=1500 where id=1;delete from user where id=2;select * from user where id=3 group by. . . Having. . . Order by.. limit

Let's take the code as an example, create a new file and define a class class. When we encapsulate the model class, we need to add member variables, such as hostname, user name, password, database name, character set and data table prefix, and then we will return a resource after we successfully connect to the database, and we need to save the resource as a member variable. This makes it very convenient for us to use it in other places, so we add the database connection resources and the table name (we can specify the table name ourselves). We often make some errors when debugging the database, so we need SQL statements and manipulate arrays to store all the query conditions.

The specific code is as follows:

Tags: Data database method variable member resource code datasheet time statement query content character set array article success host prefix password Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Docker vpn Linux