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

  • PHP 7 Programming Blueprints
  • Jose Palala Martin Helmich
  • 262字
  • 2021-07-08 11:14:10

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.

主站蜘蛛池模板: 青岛市| 砀山县| 临沂市| 金坛市| 措美县| 芦溪县| 喜德县| 太康县| 开阳县| 祁门县| 海口市| 遵义县| 大方县| 永胜县| 龙州县| 佳木斯市| 盐亭县| 清镇市| 吉隆县| 防城港市| 沙坪坝区| 博白县| 雷山县| 丰宁| 许昌县| 光泽县| 澄江县| 贵德县| 温州市| 伊金霍洛旗| 秦安县| 华亭县| 同心县| 连城县| 灵武市| 承德县| 马公市| 雷波县| 淮南市| 古交市| 巫山县|