Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize database operation in the development of Wechat public platform

Shulou Source: shulou.com Published: 2022-06-03 16:10:16 09月12日 Update

This article will explain in detail how to implement database operation in the development of Wechat public platform. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Train of thought analysis

Baidu developer Center provides powerful cloud databases (including MySQL, MongoDB, Redis). In this tutorial, we will demonstrate the operation of the familiar MySQL database to achieve the interaction between Wechat and the database.

It is very simple to use cloud database in BAE applications. The name in the database list is the dbname when connecting to the database. The user name, password, connection address, and port are taken out through the environment variable in the application.

The database can be accessed using standard PHP Mysql or PHP Mysqli extensions, which are available in BAE's PHP and can be used directly by applications.

For official documentation, please refer to: ttp://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/mysql

Create a BAE MySQL database

3.1 Log in to Baidu developer Center-> Administration Center-> Select applications-> Cloud Environment-> Service Management-> MySQL (Cloud Database)-> create a database

3.2 create a database

Note: each application has and only one database enjoys a 1G free quota, while the rest of the database does not enjoy a free quota discount. You can use this offer again only if you delete the database that has already used the free quota.

3.3 created successfully

Here you can see the name of the database, that is, dbname, which will be used later.

Click "phpMyadmin" to access the database.

3.4 phpMyadmin interface

Create a new data table, enter the table name and the number of fields, and click "execute" to create the table.

3.5 create a table

Enter the field name and field type, and then click "Save" below to complete the creation of the table.

3.6 creation completed

Modify the id field as the primary key and add AUTO_INCREMENT; to make the from_user field unique (UNIQUE) to complete the modification of the table.

The table creation operation can also be done using the following SQL statement:

CREATE TABLE IF NOT EXISTS `test_ mysql` (`id` int (11) NOT NULL AUTO_INCREMENT, `from_ user` varchar (40) DEFAULT NULL, `passt` varchar (40) DEFAULT NULL, `password` varchar (40) DEFAULT NULL, `update_ time` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `from_ user` (`from_ user`))

PhpMyAdmin operation

This is the end of the creation of the database and data table. The following code will be written to explain in detail the use of the database and data table.

Official example (PHP MySQL)

An example of demo (PHP MySQL) officially provided by BAE is as follows:

Mysql/basic.php file content

Tags: Data test database success result code statement update file function query influence retrieval field password data table error application platform development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS vpn NVidia Microsoft