Expert PHP and MySQL.pdf

(11001 KB) Pobierz
1148787920.002.png
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
1148787920.003.png 1148787920.004.png
Contents at a Glance
About the Author ������������������������������������������������������������������������������������������������������������� xvii
About the Technical Reviewer ������������������������������������������������������������������������������������������ xix
Acknowledgments ������������������������������������������������������������������������������������������������������������ xxi
Introduction �������������������������������������������������������������������������������������������������������������������� xxiii
Chapter 1: Project Organization
��������������������������������������������������������������������������������������� 1
Chapter 2: Requirements
������������������������������������������������������������������������������������������������ 23
Chapter 3: Platforms and Tools
�������������������������������������������������������������������������������������� 45
Chapter 4: The Database
������������������������������������������������������������������������������������������������ 83
Chapter 5: Application Structure
��������������������������������������������������������������������������������� �� 139
Chapter 6: Security, Forms, and Error Handling
���������������������������������������������������������� 191
Chapter 7: Reports and Other Outputs
�������������������������������������������������������������������������� 249
Chapter 8: Data Conversion
����������������������������������������������������������������������������������������� �� 283
Index������������������������������������������������������������������������������������������������������������������������������� �� 307
v
1148787920.005.png
Introduction
It’s a big step from proiciency at PHP programming to being capable of developing commercial applications. As Fred
Brooks estimated in his classic book, he Mythical Man Month (Addison-Wesley, 1995), “a programming product costs
at least three times as much as a debugged program with the same function.”
My goal in writing this book is to help you take that big step.
What do you have to know beyond PHP programming? Well, there’s project organization (including staing
and scheduling), keeping the customer satisied, identifying requirements (being agile but not sloppy), choosing the
development and production platforms, designing the database, structuring the application to handle forms and
buttons, dealing with security and error handling, and converting data from the old system to the new. hat’s also the
top-level list of topics in this book.
Pick up any of the many PHP/MySQL books in any large bookstore and you’ll ind chapters on installing PHP,
variables, statements, functions, string processing, arrays, objects, ile handling, debugging, and, probably, a toy
e-commerce site. Not this book! I assume you already know all that stuf, or can ind it somewhere if you don’t.
Instead, I tried to cover essential topics that I’ve never seen in any book, such as choosing between shared hosting
and a virtual machine in the cloud, updating a live application, translating MySQL constraint errors to something the
user can understand, protecting passwords the right way (hashed, salted, and stretched), implementing two-factor
authentication, making your web site invulnerable to attack (via SQL injection, cross-site scripting, cross-site request
forgery, or clickjacking), implementing validation with database triggers, developing reports as CSV iles or PDFs,
converting data with variant name spellings, avoiding legal disputes, and lots more that PHP/MySQL programmers
struggle with every day as they develop industrial-strength applications.
Beyond the technical details, I’ve tried to pass on what I’ve learned over the four decades I’ve spent developing
commercial software. One of my favorite quotations (the source is unknown) is, “Good judgment comes from
experience and experience comes from bad judgment.” I’m sure I’ve exhibited more bad judgment than you ever
will. I’ve had more bugs in my software, more wrong platform selections, more architectural dead ends, more
user-interface catastrophes, and more customer-support iascoes than anybody, but I like to think that’s because I’ve
been at it longer than anybody. (After all, Babe Ruth struck out 1,330 times, a number no ordinary baseball player will
ever come close to.) So my judgment is now pretty good, and you get the beneit. You can look forward to making your
own original, creative mistakes—no need to repeat mine. I hope you’ll hit a lot of home runs, too, as I have. (Figuratively.)
I’ve also tried to just give the plain answer when I know it, and the reasons why it’s the answer, instead of listing
the pros and cons and telling you to make the best choice for your situation. hat saves you time. Use PDO for your
PHP-MySQL interface, FPDF for your PDF library, MySQL Workbench for your database design tool, jQuery for your
JavaScript library, Phpass for password hashing, and my 17-section requirements outline. You don’t have to do it my
way, of course, but there are hundreds of design choices you have to make in the course of developing an application
and you can’t aford to make each one into a research project. Wouldn’t it be a relief to just be told the best way to go?
here are code examples throughout the book, all of which you can download from www.apress.com . he
principal techniques are embodied in PHP classes—Access, DbAccess, Form, Page, Report, and Security—that
are robust enough to incorporate directly into your own applications. I present the code in small, somewhat
disconnected, chunks, but you can keep from getting lost by downloading the source and following along in it as you
read through the technical explanations of why and how I did things the way I did.
xxiii
1148787920.001.png
IntroduCtIon
here are eight chapters in all, forming three groups. he irst two-chapter group, Project Organization and
Requirements , should be read together but can be skipped on irst reading if you’re anxious to get right to PHP/MySQL
programming, although I like to think that much of my most valuable insights are there. (You’ll enjoy my war stories.)
he middle four chapters, Platforms and Tools, he Database, Application Structure, and Security, Forms, and Error
Handling , form the guts of the programming part of the book and need to be read in order. he last two chapters,
Reports and Other Outputs and Data Conversion , build on the middle chapters.
At this point the author usually thanks the reviewers for their work but admits that any remaining mistakes are his
alone. Yeah, but the staf at Apress is so great, surely if anything got through it’s their fault, right? OK, I’m joking, just
trying to be funny, and probably failing at it. I hope in reading this book you ind that my other attempts at humor are
more successful. And, back to being serious, please send an e-mail to book@basepath.com if you do ind any of those
remaining mistakes. hey really are all mine. Still trying to improve my judgment.
—Marc Rochkind
Boulder, Colorado
July, 2013
xxiv
Zgłoś jeśli naruszono regulamin