Beginning PHP 5 and MySQL E-Commerce 202
Beginning PHP 5 and MySQL E-Commerce: From Novice to Professional | |
author | Cristian Darie and Mihai Bucica |
pages | 568 |
publisher | Apress |
rating | 9 |
reviewer | Mary Norbury-Glaser |
ISBN | 1590593928 |
summary | Create an E-Commerce Site Using PHP 5 and MySQL 4 |
The authors use a T-shirt shop scenario as their model for the design and implementation of their e-commerce site. The book is separated into three distinct "phases" of development. Phase I covers the foundations of creating the Web site, what tools to use and how to use them including creating a product catalog, incorporating a search tool, using PayPal payment processing and adding an administration interface. Phase II proceeds with enhancing the site with a custom shopping cart, a client-server ordering process, a page for pending order administration and a dynamic product recommendations system. Phase III looks at a more complicated customer accounts scenario: taking credit cards instead of using PayPal, building an order-processing pipeline, implementing credit card gateways, adding a product reviews system and accessing web services using SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) XML-based protocols.
Chapter 1 introduces business strategies for considering an online commerce solution and the reasons for launching an e-commerce presence: acquiring more customers, making customers spend more and reducing the costs of fulfilling orders. A thorough read of Appendix C ("Project Management Considerations") would be a good aside at this point. This section provides excellent insight into choosing an appropriate software development cycle model for different projects with a good discussion of advantages and disadvantages of various methods and theories.
Chapters 2 through 7 constitute Phase I proper. The authors begin by tackling the basic structure of the site and focusing on flexible design, scalability and reliability. They introduce a three-tier architecture model: the presentation tier (dynamic pages that contain the elements that allow visitor to the site to interact effectively with the business end), the business or middle tier (requests for data that are posed by the visitor are passed on by the presentation tier to the data tier) and the data tier (manages the data and sends appropriate responses back to the business tier when requested).
Chapter 2 lays the groundwork for the reader to establish the TShirtShop site and accompanying database. Installation instructions for Apache 2, PHP 5, MySQL 4 and phpMyAdmin are referenced to Appendix A. Instructions for installing other tools used in this book - the Smarty template framework for PHP and PEAR DB - are included within Chapter 2. I quite admire the authors' choice to use Smarty. Smarty parses templates behind the scenes and creates PHP scripts from them so when a Web page is rendered, Smarty reads from the PHP scripts instead of pulling the templates themselves, eliminating run-time parsing of templates. Smarty also has built-in caching of template outputs, which saves on overhead in retrieving data from the database.
After creating the main index.php page and the index.tpl Smarty template, the authors discuss error handling and reporting (with a nod to PHP's often head-scratching error messages). They provide a nice set of instructions here for creating an efficient error handling/reporting scheme. The last step in Chapter 2 is to load phpMyAdmin and create the new tshirtshop database and an admin user.
From this point forward, the authors structure each chapter to adhere to the three-tier model. Implementing the presentation tier, the business tier and the data tier is an integral part of the construction of the site. The reader is encouraged to begin every major aspect of the project with these elements in mind.
Chapters 3 and 4 lead the reader through the creation of the product catalog for the TShirtShop site. The authors give a brief overview of SQL, relational databases, using PEAR DB and Smarty plug-ins. The first table is created and populated with data, PEAR DB is used to access the data and a Smarty template is used to implement the user interface. Multiple tables are then added to enhance product catalog features, which allows for a discussion of table relationships. Filtering SQL results and joining data tables are then examined in the section on implementing the data tier.
Chapter 5 introduces a product search engine to the site by using MySQL to search the database and using Smarty templates to build the user interface. This is a major component of any e-commerce site and the authors prepare an excellent code set for this purpose by using the full-text searching functionality of MySQL. The pros and cons of this versus using LIKE are also discussed.
Chapter 6, "Receiving Payments Using PayPal", will be of great interest to many readers. Many individual proprietors and small businesses don't have the resources to process credit cards and therefore use Internet Payment Service Providers to process transactions. In this chapter, the authors teach the reader how to create a new PayPal account, how to integrate the PayPal shopping cart and custom checkout and how to configure PayPal to automatically calculate shipping costs. There is a bit of missing code in this chapter but it appears correctly on this book's Apress errata page (apress.com).
The last chapter of Phase I covers implementation of a catalog administration page using componentized templates and a simple authentication scheme for administrator access to the page.
By the completion of Phase I, the design and programming for a completely functional e-commerce site is in place.
Phase II begins with a pros and cons discussion of using a simple cart method like PayPal versus creating a custom shopping cart and checkout to enhance flexibility. There are some neat tricks here including storing the cart ID as a cookie on the client.
In Chapters 8 and 9, the reader learns how to store cart info in the database, how to implement a client-side ordering mechanism and an orders administration page for pending orders. The benefit to this is that since the data is now stored in the database, quantitative analysis and tracking can be done based on the products sold.
In Chapter 10, the authors add product recommendations to their TShirtShop site. This dynamic visitor-specific functionality is an excellent sales strategy intended to boost sales by adding suggestions for upgrading a purchase or complementing a purchase with another product. The items recommended are based on what products were ordered together by other customers. The SQL query to get the list of products is very nicely done!
This concludes Phase II and the site is again fully functional but with some neat new enhancements: the site has its own shopping cart, credit card processing is accomplished through PayPal and an orders administration page and product recommendations system have been added. Many individually run or small businesses may stop at this point and be completely content with the e-commerce site that has been developed so far. But the authors proceed with more complex scenarios by offering Phase III: "Processing Orders and Adding Features". This final section of the book deals with processing credit cards, using SSL to encrypt data transactions, storing customer accounts, adding a customer product review system (think Amazon.com) and using XML Web services to integrate Amazon.com products into the site.
The authors spend some time covering the design of the order pipeline and optimizing the logical sequence of tasks that need to be tracked. Chapter 12 deals with the modifications necessary to the enable pipeline processing and the database schema changes for auditing and storing data. Chapter 13 implements the pipeline sections in preparation for adding full credit card transaction functionality in Chapter 14 and rounds out with the creation of a new orders admin page that shows an audit trail for any particular order stored in the database.
Full implementation of credit card orders is completed in Chapter 14. The authors discuss credit card transaction fundamentals including working with credit card payment gateways, understanding transactions and card processing. They look at two payment services providers as examples: DataCash (a UK-based company) and Payflow Pro (a division of Verisign).
Product review integration is the subject of Chapter 15. This is another highly coveted enhancement to e-commerce sites. The authors provide a very simple (and therefore, elegant, in my view) implementation of code to add review capabilities to the sample site.
The final chapter of the book is Chapter 16, "Connecting to Web Services", where the authors complete their professionally developed TShirtShop e-commerce site by integrating the Amazon E-Commerce Service using SOAP and REST.
Appendices A-C cover necessary application installation (as mentioned above), hosting advice, steps for getting your files where they need to be on various hosting models and project management theory. Access to code and errata is available on the Apress Web site (apress.com). This book has a nice layout, clean typography, plenty of screen shots and the code sets are offset from the main body of text and are extremely easy to follow. The book can readily be propped open while looking on from your development machine and the overall size of the book isn't unwieldy or awkward to place on a surface.
In the The Expert's Voice in Open Source series, Apress has harnessed the knowledge and expertise of some of the best folks in open source and this book is no exception. Cristian Darie has previously written several well-regarded volumes (Programmer's Guide to SQL, Beginning ASP.NET E-Commerce, Visual C# .NET: A Guide for VB6 Developers, among others) and his skill in untangling complex subject matter is apparent in Beginning PHP 5 and MySQL E-Commerce. Both authors have prepared a book that will enable any intermediate developer to create a fully functional e-commerce Web site that they can then customize and extend. This book is consistent, well organized and clearly presented. Beginning PHP 5 and MySQL E-Commerce: From Novice to Professional is the perfect tutorial-style book for start-to-finish e-commerce site development instruction for any developer with the desire to learn the advanced tools and techniques to get a scalable professional site designed and in production.
You can purchase Beginning PHP 5 and MySQL E-Commerce: From Novice to Professional from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
my God! (Score:3, Funny)
Re:my God! (Score:1, Offtopic)
Re:my God! (Score:1, Offtopic)
Looks like Timothy needs to read this himself.
Oh wait, Slashdot runs on Perl
Thank you, I'm here all week.
Re:my God! (Score:1)
Re:my God! (Score:2, Funny)
Re:my God! (Score:2)
Re:my God! (Score:1)
Holy Shit (Score:2, Insightful)
Re:Holy Shit (Score:1)
that's it! (Score:1, Offtopic)
I'm not asking. (Score:5, Funny)
Re:I'm not asking. (Score:2)
Poor editing (Score:4, Funny)
Re:Poor editing (Score:3, Funny)
1. Bang head against wall, repeatedly.
2. ????
3. Profit!
OffTopic: Display Error (Score:1, Offtopic)
Someone needs to clip it down...
Re:OffTopic: Display Error (Score:3, Interesting)
Re:OffTopic: Display Error (Score:5, Funny)
where is the painter in HomoNettMail?
Re:OffTopic: Display Error (Score:2, Funny)
Um, no (Score:2)
Internet Broke (Score:2)
Ads on Slashdot (Score:1, Funny)
TMF? (Score:1)
weird.
So Mr OWL (Score:3, Funny)
Well... (Score:1)
JEEEbus PRICEd (Score:1)
Lenght of comment threads. (Score:2, Offtopic)
5 minutes later... (Score:2)
5 Minutes Later? (Score:2)
why stop with the review (Score:4, Funny)
WTF? (Score:1)
Re:WTF? (Score:2)
In fact, they are. Notice the affiliate links on all book reviews. Used to be Amazon, but BN apparently pays them more now.
Timothy (Score:1, Offtopic)
Reboot didn't fix. (Score:2, Funny)
I've already rebooted so don't tell me that will fix the problem.
Guess I'll just spend the afternoon reinstalling Windows98 again.
Don't bother... (Score:1, Offtopic)
Why oh why? (Score:5, Informative)
Also, usability is a large factor. Unless you're Jakob Nielsen, you are likely to overlook some design choices that will result in lost sales and lost opportunity. Unfortuantely, all too often the person writing the card is not the one that should be doing the site design.
If you don't want to spend the money for a hosted or installed cart, there are some free / OSS alternatives such as ZenCart [zen-cart.com] or OSCommerce [oscommerce.com].
The bottom line is that most stores don't need the hassle, cost, and complexity of a custom cart solution. Remember to look at total cost of ownership.
Even better... (Score:3, Informative)
I disagree... (Score:3, Insightful)
Re:Even better... (Score:2)
And if anyone is interested in that success, there's book about e-commerce webdesign [greenspun.com] from the guy who wrote Yahoo! Shopping.
Re:Why oh why? (Score:1)
I think you're missing the point. (Score:2)
Ok, admittidly 80% of the world doesn't need to worry about the mechanics of how to make it happen, but the other 20% might be looking for this kind of book to use as a learning/refrence guide.
Re:Why oh why? (Score:2)
Re:Why oh why? (Score:2)
Re:Why oh why? (Score:3, Informative)
Plus, it REQUIRES register_globals which is a huge security risk. However, they are smart enough to use transactions (or at least the presence of innodb tables...) And, if I remember correctly, they store credit card numbers in the clear... Also, the last official release was in 2003 (2004 if you count the OSC Max version at aabox.com)
What's nice is it installs very easily.
Really? (Score:2)
Timothy!!!!! (Score:3, Insightful)
The master of dupes has now just crossed the line into master of stupidity.
*watches his karma go down faster than a $2 vegas whore.*
Re:Timothy!!!!! (Score:2)
There's a trend on
Now, I'll probably get modded down for telling you this...
Eureka! I've figured out the internets (Score:1)
I'm a whiz at fixing computers
Fixed in a Few Mins (Score:2, Funny)
Its not like we are all sitting at are computers trying to be the first to post on a news story and forbid there be a error in the post.... or are we.....
Oh wait I am one of those sitting at my computer waiting to post.....
Not sure I'm comfortable with this idea... (Score:4, Funny)
Oh, and since nobody else has pointed it out, I think the whole review is on the front page.
in time for the Montreal PHP Conference (Score:2)
dude.....sweet! (Score:1)
groundbreaking! (Score:3, Funny)
you didn't really read this chapter and just wanted to make sure you wrote something about each one, huh?
Re:groundbreaking! (Score:2)
I sure hope that people who read that chapter also take time to read how cookies can be abused.
Like The Twelve Most Common Application-level Hack Attacks [watchfire.com](102 KB pdf)
Note The linked article is good reading for new web programmers but probably old news for many programmers here.
Oh wow! (Score:1, Offtopic)
PHP 5 and MySQL for the uncreative (Score:1)
Don't start from scratch (Score:5, Informative)
If you need ecommerce, or any web application for that matter, then there is no point in starting from scratch.
There are plenty of platforms or frameworks out there that you can build on.
My own favorite is Drupal [drupal.org] which is not just a Content Management System, but rather an open framework.
For example, some creative guy wrote an Ecommerce [drupal.org] set of modules for Drupal, so it can do just that.
Re:Don't start from scratch (Score:2)
My favorite is: Open Source E-Commerce [oscommerce.com].
Re:Don't start from scratch (Score:2)
Re:Don't start from scratch (Score:2)
Re:Don't start from scratch (Score:2)
Anyone care to comment on which might be a better ecommerce platform to start with?
Using PHP5 (Score:2)
Re:Using PHP5 (Score:1)
Is there any PHP book *not* for beginners? (Score:5, Interesting)
Stuff like: Bayesian inference [ibm.com], Probability models [ibm.com], Web site user modeling [ibm.com], etc.
All of those examples are from the same author (the guy in charge of phpmath.com [phpmath.com]), but go to show that there are actually interesting things being done with PHP.
I'd love to see some books that *don't* spend 200 pages explaining how to get to fetching an array from MySQL.
What would you want to see? (Score:2)
To that end, one PHP book that did have some good advanced sections was George Schlossnagle's book "Advanced PHP Programming" (I think that's the title).
Recently, a colleague of mine wrote a path finding algorithm in PHP to be able to
Re:Is there any PHP book *not* for beginners? (Score:2, Informative)
b4n
chapter on security? (Score:3, Insightful)
Re:Ugh... editors at it again... (Score:1)
XD
Re:Ugh... editors at it again... (Score:2)
it may help them fix the system.
;)
Batman! (Score:3, Funny)
Re:Batman! (Score:1)
Re:Note to /. editors: (Score:1, Offtopic)
How ironic.
Re:Note to /. editors: (Score:2)
If everyone's talking about the front page screwup, isn't that the topic?
hehehe, nice one (Score:1)
+1 Informative indeed.
Re:hehehe, nice one (Score:1)
Re:hehehe, nice one (Score:2)
Bah, I even posted my "php ?> sucks" response to that troll.
Re:My experience (Score:2)
$why_php_sucks = "this ?> is why"
Let's see, what else
It appears that Bruce Perens and his staff have now embr
Re:My experience (Score:2)
So there's a language that doesn't need escapes? Which one?
Re:My experience (Score:2, Informative)
$why_you_are_wrong="this ?> is why";
works just fine here. PHP 4.3.10.
Re:That's a long summary! (Score:1)
Re:That's a long summary! (Score:1, Offtopic)
<suave>Why, thank you.</suave>
Re:A store using MySQL? (Score:1, Insightful)
Re:A store using MySQL? (Score:2)
No. I just understand databases a hell of a lot better than your average PHP hack, due to years of experience.
Re:A store using MySQL? (Score:1)
Re:A store using MySQL? (Score:1)
E-commerce should never be handled with MySQL.
Is that clear enough for ya'?
Re:A store using MySQL? (Score:1)
I'm looking for specific reasons as to why you hold this opinion.
Is that clear enough for ya?
Re:A store using MySQL? (Score:2)
Re:A store using MySQL? (Score:2)
Re:A store using MySQL? (Score:2)
I immediately write off as "clueless" any author that suggests that MySQL is a good tool to use for things that require security like shopping carts, or for anything close to mission critical.
I guess SAP is well, clueless, being that MySQL MaxDB [sap.com] has been their open source database of choice for years.
You silly sausage . . . check your facts first next time before posting such knee-jerk drivel.
Re:A store using MySQL? (Score:2)
> I guess SAP is well, clueless, being that MySQL MaxDB has been their open source database of choice
> for years.
MaxDB? Ah, "Adabase". That heap of 70s technology has been around for at least 20 years, and predates most relational databases. The product was probably open-sourced since it is reliable with data - and so a great addition to the mysql stable. However, it's been a 'has-been' in the d
Re:A store using MySQL? (Score:2)
Completely different db than MySQL.
Re:A store using MySQL? (Score:1)
Re:A store using MySQL? (Score:4, Insightful)
Most credit card processing back ends will give your application transaction id's which can be used to complete a transaction, reverse it, etc. all without ever needing the credit card number itself.
Similarly, the personal information that's collected for the purposes of things like shipping should be pulled off the web server in most cases. For most of my clients, we set them up with a firewalled internal server that pulls down that information on a daily basis. Also remember that for the VAST majority of ecommerce, it's not like the whole process happens without human intervention. In most cases, only a provisional transaction (that expires if not followed up) takes place automatically. The "real" transaction only happens when someone actually fulfills the order (after a human being is done reviewing it).
Doing a few things like this result in nothing being stored on the server that isn't available in the phone book, tax records or otherwise publicly available.
Information security starts long before you pick a database server and extends way beyond it as well.
Personally, I write off anyone who indicates that they'd store credit card numbers in *any* database without a REALLY good reason.
Re:A store using MySQL? (Score:2)
Beyond that, I wouldn't trust CC info in any database. The method I use is to split up the storage of CC info, one part to one database, another to another database on another machine and the key stored on another. It's a bit of a pain in the ass to set up, but it would take one helluva of a catastrophe for a hacker to steal CC info. Note that whether I was using MySQL, Oracle, MS-SQL or someother db server, this would apply.
Still, I'd love to know
Re:A store using MySQL? (Score:2, Interesting)
Doesn't matter what DB you use... (Score:3, Insightful)
Just tried looking at a product detail and then adding to cart from there in Firefox 1.0.1 and it doesn't work.
Ah! I see now, your database keeps card details secret by never storing them at all, genius!
Seriously, MySQL is a lot of things but insecure on a well firewalled box it isn't. My companies e-commerce package uses postgresql by default but can fall back on MySQL (with a few cludges to get around limitations) if that's all that is available.
Re:Doesn't matter what DB you use... (Score:2)
Ya, and I've seen a dozen companies that managed mission-critical data within the complex and often incorrect spreadsheets of secretaries insecure pcs.
So? The fact that company x doesn't care about data quality problems says more about the company's competance than about the importance of those problems.
There's a world of difference between... (Score:2)
True, for anything more complex than a blog, simple content managed website, forum or e-commerce system you want to use something more robust (with stored procs, triggers, sub-queries and the like) but for an awful lot of what people want to do, MySQL is Good Enough (tm), and it requires virtually zero administration, that's the real pull (and why you find
Re:There's a world of difference between... (Score:2)
> but for an awful lot of what people want to do, MySQL is Good Enough (tm), and it requires virtually
> zero administration, that's the real pull (and why you find MySQL available on every damn hosting
> account out there).
Hmm, I think
Re:Blurb is a mile long (Score:2)
No, you are presuming that
In actuality, when editors fuck up here they get promoted.
Re:Here's a Q: (Score:2)
But that's just me.