简体   繁体   中英

Best practice for PHP without the use of a database? [on hold]

Background

I am learning web development and I have some basic understandings on React and jQuery. I'm practicing using PHP also. Now I want to make a simple shopping cart - for myself, the least complicated as I'm still a newbie- which will offer functions such as adding product , clear the cart , modify product quantity in cart ,... I'll use React by create-react-app and jQuery. I run PHP on Apache server provided by XAMPP.

Question

I heard it can be done without the use of a database. However, I don't know how I should use my PHP files, in this case, for. Can I use it to store data and echo JSON back when I call jQuery requests on my React side? Or there is a better way to do? I would appreciate any help.

You would not need to store items in the database unless you are looking to do things like Abondoned cart marketing or some other form of future data management of customers current carts.

Shopping carts are generally made using a SESSION. You would normally recieve and process the cart action with a switch control statement (Dont worry that may be alient words to you). When the user clicks the add to cart button it will fire off to the backend PHP script you make. The PHP switch code maanaged the add to cart, remove from cart and empty cart actions.

A PHP SESSION is a way to store information using varibles across multiple pages.

Visit W3Schools on SESSIONS

PHPPot has a valuable example which you should learn off of. Its a great example. SESSION Example

The issue you will face is due to not having a database, the website has no where to store all your customers sessions. So everytime they visit the websites they will lose their shopping cart - most likely.

You could possibly use a Cookie to store the data on a users computer instead, however you then start to balance the GDPR factor into your website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM