Lesson 8: Retrieving Auction Records from the Database

Introduction

In the previous lesson, we created our first Auction Manager class and added the create_auction() method. Although the method is capable of inserting auction records into the database, we haven’t used it yet. As a result, our wp_flipnzee_auctions table is still empty.

Before building forms or administration pages, it’s important to learn how to retrieve information from the database.

Professional software is built in layers. First we create the database, then we build classes that communicate with it, and only afterwards do we create user interfaces.

In this lesson, we’ll expand the Auction Manager by adding methods that retrieve auction records from the database.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Retrieve a single auction by its ID.
  • Retrieve all auctions.
  • Understand WordPress’s $wpdb->get_row() method.
  • Understand WordPress’s $wpdb->get_results() method.
  • Continue separating database logic from presentation.

Why Read Before Writing?

Most applications spend far more time reading data than writing it.

Think about Flipnzee.

Visitors browse listings.

Buyers search auctions.

Search engines index pages.

Administrators review sales.

All of these activities require reading data from the database.

Learning to retrieve records is therefore just as important as learning to create them.


Step 1 – Open the Auction Manager

Open:

includes/class-auction-manager.php

We’ll keep our existing create_auction() method.

Now we’ll extend the class.


Step 2 – Add a Method to Retrieve One Auction

Add the following method below create_auction().

/**
 * Retrieve one auction by ID.
 *
 * @param int $auction_id Auction ID.
 *
 * @return object|null
 */
public static function get_auction( $auction_id ) {

	global $wpdb;

	$table = $wpdb->prefix . 'flipnzee_auctions';

	return $wpdb->get_row(
		$wpdb->prepare(
			"SELECT * FROM {$table} WHERE id = %d",
			$auction_id
		)
	);
}

Understanding get_row()

This method retrieves a single record.

If the auction exists:

Auction #15

it returns one object.

If the auction doesn’t exist:

Auction #999

it returns:

null

Why Use $wpdb->prepare()?

Never insert user input directly into SQL queries.

Instead of writing:

SELECT * FROM table WHERE id = $auction_id

we write:

$wpdb->prepare(...)

WordPress safely prepares the query before sending it to MySQL.

This helps protect your plugin from SQL injection attacks.


Step 3 – Retrieve All Auctions

Now add another method.

/**
 * Retrieve all auctions.
 *
 * @return array
 */
public static function get_all_auctions() {

	global $wpdb;

	$table = $wpdb->prefix . 'flipnzee_auctions';

	return $wpdb->get_results(
		"SELECT * FROM {$table} ORDER BY created_at DESC"
	);
}

Understanding get_results()

Unlike get_row(),

get_results()

returns multiple rows.

If the database contains:

Auction 1

Auction 2

Auction 3

you receive an array containing three objects.

If there are no auctions yet:

you receive an empty array.


Why Aren’t We Showing Results Yet?

You might wonder:

Why don’t we display these auctions immediately?

Because our plugin still doesn’t have an administration page.

For now, we’re building the backend.

Soon, the administration interface will simply call these methods.


Our Growing Auction Manager

Our class now contains:

create_auction()

get_auction()

get_all_auctions()

Soon we’ll add:

update_auction()

delete_auction()

close_auction()

Notice how everything related to auctions stays inside one class.


Lesson Summary

In this lesson, we expanded the Auction Manager by adding methods to retrieve auction records from the database.

Although our table currently contains zero records, our plugin is now capable of reading both individual auctions and complete auction lists.

This prepares us for building the administration interface in future lessons.


Key Takeaways

  • ✓ Use get_row() when retrieving one record.
  • ✓ Use get_results() when retrieving multiple records.
  • ✓ Always use $wpdb->prepare() with user input.
  • ✓ Keep database operations inside dedicated classes.
  • ✓ Build the backend before the user interface.

Common Mistakes

  • Writing raw SQL with user input.
  • Mixing SQL with HTML.
  • Forgetting to use $wpdb->prepare().
  • Returning multiple rows when only one is expected.

Git Commands Used

git add .

git commit -m "Lesson 8: Retrieve auction records"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

✅ Retrieve auction records

⬜ Create admin menu

⬜ Create first auction

⬜ Bid engine

⬜ Escrow workflow

⬜ Website transfer

⬜ Notifications

⬜ Version 1.0

Project Evolution

Throughout this project, we’ve been refining the architecture as new requirements become clearer.

One important decision was separating listing management from auction management. Website information remains the responsibility of Flipnzee Analytics, while Flipnzee Auctions focuses on auction logic and transaction workflows.

This lesson continues that philosophy by keeping all database operations inside the Auction Manager rather than scattering SQL queries throughout the plugin.

As always, the GitHub repository contains the latest implementation, while these lessons document the reasoning behind each architectural decision.


Developer’s Notebook

One of the easiest ways to identify well-structured software is by looking at how it accesses the database. Instead of allowing every part of the application to execute SQL queries, professional developers usually centralize database operations inside dedicated classes. This makes the code easier to test, easier to debug, and much simpler to extend. As Flipnzee Auctions grows to include bidding, escrow tracking, and website transfers, this design will allow us to add new functionality without creating unnecessary complexity.


Looking Ahead

In Lesson 9, we’ll create our first WordPress Administration Menu for Flipnzee Auctions. Instead of interacting with the database directly, administrators will begin managing auctions through the WordPress Dashboard. This marks the transition from backend infrastructure to a real user interface.

How to Verify That Your WordPress Plugin Created a Database Table (Hostinger phpMyAdmin & Other Methods)

When developing a WordPress plugin, one of the most satisfying moments is seeing your first custom database table appear.

In our Flipnzee Auctions series, we created the wp_flipnzee_auctions table using WordPress’s dbDelta() function.

But how do we know the table was actually created?

There are several ways to verify this. In this article, I’ll show the method I used while developing Flipnzee Auctions on Hostinger, along with several other approaches that work on different hosting providers.


Why Verify the Database?

Suppose you activate your plugin and nothing appears to happen.

Did the activation hook run?

Was the SQL correct?

Did dbDelta() create the table?

Rather than guessing, it’s always a good idea to verify the database.


Method 1 – Using Hostinger phpMyAdmin (Recommended)

Since Flipnzee.com is hosted on Hostinger, this is the method I personally used.

Step 1

Log in to your Hostinger hPanel.


Step 2

Open:

Websites → Manage

for your WordPress website.


Step 3

Open:

Databases → phpMyAdmin


Step 4

Select your WordPress database.

You’ll see all WordPress tables listed in the left sidebar.


Step 5

Scroll through the list.

After activating the Flipnzee Auctions plugin, I found the newly created table:

wp_flipnzee_auctions

This confirmed that the activation hook executed successfully and that WordPress created the database table.


My Development Screenshot

The following screenshot shows the actual database used while developing the Flipnzee Auctions plugin.

Notice the presence of the wp_flipnzee_auctions table among the standard WordPress tables.


Method 2 – phpMyAdmin on Other Hosting Providers

Most shared hosting providers offer phpMyAdmin.

For example:

  • cPanel Hosting
  • Bluehost
  • SiteGround
  • DreamHost
  • A2 Hosting
  • Namecheap Hosting

The process is almost identical:

  1. Open phpMyAdmin.
  2. Select your database.
  3. Look for your custom table.

Method 3 – MySQL Workbench

Many professional developers use:

  • MySQL Workbench

Connect using your database credentials.

Refresh the database.

Your custom table should appear automatically.


Method 4 – Adminer

Adminer is a lightweight alternative to phpMyAdmin.

Many developers prefer it because it’s fast and easy to use.

Simply connect to your database and check whether your table exists.


Method 5 – DBeaver

Another popular database tool is DBeaver.

It’s free and supports multiple database systems.

After connecting to your WordPress database, simply refresh the tables list.


Method 6 – Create an Admin Dashboard (Future Lesson)

As our plugin evolves, we won’t need to open phpMyAdmin every time.

Instead, we’ll build an administration page inside Flipnzee Auctions that displays information such as:

Plugin Status

✓ Plugin Active

✓ Database Connected

✓ Auction Table Exists

Version 1.0.0

This provides a much friendlier experience for plugin users.

We’ll build this later in the series.


Which Method Should Beginners Use?

If you’re just getting started with WordPress plugin development, phpMyAdmin is usually the easiest place to begin because it lets you see exactly what’s happening behind the scenes.

As you become more experienced, you’ll probably rely more on dedicated database tools or build your own plugin diagnostics.


Lesson Learned

Creating a database table is only half the job.

Professional developers always verify that the database matches what the code intended to create.

Developing the habit of checking your database after major schema changes can save hours of debugging later.


Final Thoughts

One of the goals of the Flipnzee Auctions project is not just to build a marketplace plugin, but to understand what happens behind the scenes as WordPress plugins interact with the database.

Learning to inspect your database is an important step toward becoming a confident WordPress developer.

As we continue this series, we’ll gradually move from simply creating tables to inserting records, updating them, retrieving data, and eventually powering a complete website marketplace.