wordpress transaction transaction processing, transaction processing in wordpress mall payment

In the process of developing the WordPress payment plug-in,
transaction processing needs to be used,
but after reading the official documents, I
found that there are few relevant instructions.

1. WordPress does not support transaction transaction processing
1-1) After carefully looking at the data table structure of WordPress,
they are all of myisam type,
which cannot support transactions.

wordpress store

1-2) $wpdb has no global transaction operation methods and functions.
$wpdb is the class for wordpress operation database. There is no transaction operation in the
official document .

Looking at the source code,
there is nothing.

This may be related to the positioning of wordpress,
mainly for the blog system, which is
used to develop news and information websites, and
does not use affairs.

However, enterprises use wordpress to do e-commerce websites and online stores.
At this time, they need to use transaction transactions...

Hit here to
watch the WordPress Plugin Development video series

2. The method of using transaction transaction in wordpress
2-1) Create innodb transaction table
Since the myisam data table does not support transactions,
you cannot use the wordpress system table for transaction transactions. You need to create your own
when developing plugins or templates.
The data table, the
table engine is innodb.

2-2) Use your own database operation classes and methods
Since $wpdb does not provide transaction operation methods such as rollBack(), commit(), etc.,
you need to open the transaction yourself,
and use rollBack() and commit() in the business logic

In php development,
usually use mysqli or pdo to encapsulate transaction operations.

3. mysqli, pdo encapsulate transaction transactions and use wordpress database information
Since transactions are developed in wordpress, in
order to be compatible with wordpress,
when encapsulating transactions,
wordpress database connection information will be used
instead of writing the connection information to death.

Here you need to obtain the wordpress database connection information in the plugin,
including the database address, database login account and password, and the database corresponding to wordpress.

To get this information,
you can use the global variable $wpdb.

Click here to
learn about "wordpress uses $wpdb to get database address, account number and password"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263658&siteId=291194637