Larry Ullman

Translating Geek Into English

“Effortless E-Commerce with PHP and MySQL” Book Available Online

My forthcoming “Effortless E-Commerce with PHP and MySQL” book is now available to read via Safari Books Online. Through the Rough Cuts series, you can read this book as I write it, and even provide feedback that could affect the final text. I just completed Chapter 9, which means there are two more chapters left in the third part of the book. It looks like Part IV of the book will have two chapters as well. I’m hoping to wrap up the first draft of the book over the next two weeks.

MySQL Stored Procedures

In the book I’m currently writing, “Effortless E-Commerce with PHP and MySQL”, I’m using stored procedures for one of the two e-commerce sites being developed. Stored procedures, in case you’re not familiar with them, are blocks of code stored in the database. You can kind of think of them like defining your own functions in PHP, although I have to be careful in saying that as MySQL also supports stored functions, which are different in usage than stored procedures, but the premises are similar.

I’m using stored procedures for two reasons. First, they’re more secure, as they hide database details and create an interface that makes it impossible for hackers to adversely manipulate the database. Stored procedures also use a different permissions system, which is an added security benefit. Second, in the book’s example site, I use somewhat of an MVC (Model-View-Controller) approach, separating the data (MySQL), the visual interface (HTML), and the logic (PHP). (To be clear, the site does this without using Object-Oriented Programming or a framework.) The MVC design creates very clean, autonomous files (for example, there’s not an iota of HTML in the PHP scripts and the only queries run are along the lines of CALL stored_procedure_name()). Furthermore, the MVC-based site should scale well, as you can throw server resources at just the parts that need the most help. You can also apply specific caching techniques to each part of the equation.

MySQL :: Using the New MySQL Query Profiler

I’m in the process of writing my latest book, “Effortless E-commerce with PHP and MySQL”, and as part of the process of writing any book, there’s lots of research involved. I want to check that I’m saying the right technical things (of course), but I also want to make sure that I’m doing things in an optimal way, that I’m using all the features and resources available to me, that I’ve reflected any recent changes in technology, etc. During this process, I just came across this article on MySQL’s SQL Profiler: Using the New MySQL Query Profiler. I was looking for the best way to time the execution of various queries (specifically to compare straight SQL with stored procedures) when I saw this, and I was glad I did.

I’ll leave it up to you to read the full article, but the gist of it is that if you’re using MySQL 5.0.37 or greater and using the command-line mysql interface, you can enable profiling to see exact performance numbers for the queries you run. You can even see the nitty-gritty details: everything MySQL does to run the query, how long each step takes, and even what CPU or memory usage was required.

First Example from “Effortless E-commerce with PHP and MySQL” Online

For those of you interested in my forthcoming “Effortless E-commerce with PHP and MySQL” book, you can now look at the first example site at http://ecom1.dmcinsights.com. This project is covered in Part II of the book (four chapters total) and demonstrates:

  • Selling access to content (i.e., selling virtual products)
  • User management
  • Content management via administrative pages
  • Using PayPal’s Website Payments Standard system

There are instructions on the site for how you can access it and you can even download all the source code. There’s a form on every page through which you can ask questions or post comments. I welcome any and all feedback you may have!

I’m currently developing the second example site now, and will also make that publicly available when it’s ready. Thanks!

What is Larry Thinking? #30 => E-Commerce, E-Commerce, and E-Commerce (But Nothing About Cows)

In this edition…

About This Newsletter

So it’s been about six weeks since my last newsletter, or roughly twice as long as I normally hope I get these things out. The cause for the delay is simple: I’ve been working night and day on my forthcoming “Effortless E-Commerce with PHP and MySQL” book, trying to make the end-of-this-month deadline. I don’t think I will, but it’ll be close. Anyway, this newsletter has some stuff about that book that you may be interested in, along with a couple of other notable things I’ve found online. I went looking for some good questions to answer in this newsletter, but didn’t have any set aside, so if you’ve got a question you’d like me to answer in a future newsletter, including one you’ve previously submitted but I apparently ignored, please send it along. As always, thanks for reading and for your interest in my work!

Handling Related Models in Yii Forms

Normally two Models in an MVC architecture are related to each other, such as Employees and Departments (to use the classic example), where each employee is in one department and each department has multiple employees. Although Yii does a great job of auto-generating most of the code you need, including the form used to create and update a Model, the Yii-generated form won’t properly represent the related Model. In this post I’ll walk you through what you need to do to make your forms work properly for related Models.