Skip to content

Instantly share code, notes, and snippets.

@5iDS
5iDS / wpdb-transactions
Created June 30, 2013 22:37
MySQL database transaction, using the WordPress database object $wpdb. When you render a page in WordPress (front end or admin area), the $wpdb database object has already been initialised and opened up a connection to the database. Therefore we can recycle this database connection for our own needs. The $wpdb object saves the database handle as…
<?php
global $wpdb;
// @ prefix used to suppress errors, but you should do your own
// error checking by checking return values from each mysql_query()
// Start Transaction
@mysql_query("BEGIN", $wpdb->dbh);
// Do some expensive/related queries here