官术网_书友最值得收藏!

Chapter 2. Build a Database Class and Simple Shopping Cart

For our previous app, which was just user profiles, we only created a simple Create-Read-Update-Delete (CRUD) database abstraction layer - basic stuff. In this chapter, we will create a better database abstraction layer that will allow us to do more than just basic database functions.

Aside from the simple CRUD features, we will add result manipulation into the mix. We'll build the following features into our database abstraction class:

  • Conversion of integers to other, more accurate numeric types
  • Array to object conversion
  • firstOf() method: Allows us to select the first of the results of a database query
  • lastOf() method: Allows us to select the last of the results of a database query
  • iterate() method: Will allow us to iterate over the results and return it in a format we will send to this function
  • searchString() method: looks for a string in a list of results

We may add more functions as and when we might need them. Towards the end of the chapter, we will apply the database abstraction layer to build a simple Shopping Cart system.

The Shopping Cart is simple: a user who is already logged in should be able to click on some items for sale, click on add to shopping cart, and get the user's details. After the user has verified their items, they then click the button to purchase and we'll transfer their Shopping Cart items into a purchase order where they will fill in the delivery address, and then save this into the database.

主站蜘蛛池模板: 东方市| 鄱阳县| 中江县| 云龙县| 龙川县| 碌曲县| 五台县| 沈丘县| 罗田县| 盐津县| 二连浩特市| 革吉县| 陵水| 乌拉特前旗| 龙游县| 梓潼县| 辽阳县| 青浦区| 永和县| 旅游| 图木舒克市| 涞源县| 巴彦县| 霍邱县| 抚顺市| 伽师县| 洛川县| 平原县| 东阳市| 湘西| 凤冈县| 米泉市| 枣阳市| 南康市| 长治市| 河源市| 涟水县| 嘉黎县| 沙河市| 洪江市| 陇川县|