![]() $orders = $orders_db->get_orders( array( 'number' => 10, 'orderby' => 'total' ) ) That would retrieve all orders made with the email address example to retrieve the 10 most valuable orders, in terms of purchase total: $orders_db = new PW_Orders_DB $orders = $orders_db->get_orders( array( 'email' => ) ) It will provide a way to easily retrieve order records from the database and will include options to specify the number of orders to retrieve, the sorting method, and several other parameters.įor example, our method will permit queries like this: $orders_db = new PW_Orders_DB The get_orders() method is the primary class method that will be used the most. The constructor, which is invoked automatically when the class is instantiated, does nothing more than define the name of our table, the primary column, and the version number. Let’s start with the _construct () method. MethodsĪs before, we will go over each method and detail what it does and how it works. They are trivial to write once the foundational concepts are solid. We could also write additional methods, such as get_order(), but those are not necessary for this tutorial. create_table() – This will create our database table.count() – This will count the number of orders.get_orders() – This will return an array of order objects.get_column_defaults() – This will retrieve default values for each column.get_columns() – This will retrieve an array of table columns and their data types._construct() – This will define our table name, primary column ID, and the table version.Since we are extending the base class, we will only need to write a few new methods. Our orders class will extend the base class, meaning all of these methods are accessible in our orders DB class. We will name our new class PW_Orders_DB. Looking back at our base database class, we have the following methods: It is intended that the class we write in this tutorial be a foundational API and not necessarily a complete one. Note: this is meant purely as a sample and could be extended much further depending on your specific needs. ![]() For this part, we’re going to look at what an orders table might look at and build the database class for interacting with the orders table. In the previous part of this series we wrote the base class that we can then extend for each table in our database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |