《Head First PHP & MySQL(中文版)》：发现数据库驱动的动态网站背后的秘密，避免Web表单的尴尬遭遇，把所有关键语法直接载入大脑，关联PHP和MySQL代码，通过数千个练习巩固你的脚本知识。
是不是准备把你的静态：HTML页面上升到新高度，想要使用PHP和MySQL构建数据库驱动的网站？《Head First PHP & MySQL(中文版)》正是你需要的实践指南，可以让你很快地建立并运行动态网站。你可以具体动手构建真实的应用，包括从一个视频游戏高分公告板到一个在线约会网站等大量应用。读完《Head First PHP & MySQL(中文版)》，你将学会如何验证表单，使用会话ID和cookie、完成数据库查询和联接、处理文件I／O操作等。我们认为，你的时间如此宝贵，不应过多地浪费在与新概念的斗争中。通过使用认知科学和学习理论的最新研究成果，你将享受一种多感官学习体验，《Head First PHP & MySQL(中文版)》采用了一种专门为你的大脑而设的丰富格式娓娓道来，而不是长篇累牍地说教，让你昏昏欲睡。
If you’re ready to create web pages more complex than those you can build with HTML and CSS, Head First PHP & MySQL is the ultimate learning guide to building dynamic, database-driven websites using PHP and MySQL. Packed with real-world examples, this book teaches you all the essentials of server-side programming, from the fundamentals of PHP and MySQL coding to advanced topics such as form validation, session IDs, cookies, database queries and joins, file I/O operations, content management, and more.
Head First PHP & MySQL offers the same visually rich format that’s turned every title in the Head First series into a bestseller, with plenty of exercises, quizzes, puzzles, and other interactive features to help you retain what you’ve learned.
Use PHP to transform static HTML pages into dynamic web sites
Create and populate your own MySQL database tables, and work with data stored in files
Perform sophisticated MySQL queries with joins, and refine your results with LIMIT and ORDER BY
Protect your data from SQL injection attacks
Use regular expressions to validate information on forms
Dynamically display text based on session info and create images on the fly
Pull syndicated data from other sites using PHP and XML
Throughout the book, you’ll build sophisticated examples — including a mailing list, a job board, and an online dating site — to help you learn how to harness the power of PHP and MySQL in a variety of contexts. If you’re ready to build a truly dynamic website, Head First PHP & MySQL is the ideal way to get going.
A collection of images from inside the book.
Table of Contents
- It’s Alive: Add Life to Your Static Pages
- How It Fits Together: Connecting to MySQL
- Creating Your Own Data: Create and Populate a Database
- Your Application on the Web: Realistic and Practical Applications
- When a Database Just Isn’t Enough: Working With Data Stored in Files
- Assume They’re All Out to Get You: Securing Your Application
- Remember Me?: Building Personalized Web Apps
7.5. Sharing is Caring: Eliminate Duplicate Code
- Harvesting Data: Control Your Data, Control Your World
- Better Living Through Functions: String and Custom Functions
- Rules for Replacement: Regular Expressions
- Drawing Dynamic Graphics: Visualizing Your Data… and More!
- Interfacing to the World: Syndication and Web Services
- The Top Ten Topics (We Didn’t Cover): Leftovers
- A Place to Play: Set Up a Development Environment
- Get Even More: Extend Your PHP
What you should know before reading this book
This is a learning experience, not a reference book. We deliberately stripped out everything that might get in the way of learning whatever it is we’re working on at that point in the book. And the first time through, you need to begin at the beginning, because the book makes assumptions about what you’ve already seen and learned.
We begin by teaching simple programming concepts and database connection basics, then more complicated PHP functions and MySQL statements, and finally more complex application concepts.
While it’s important to create applications that allow users to add data to and retrieve data from your web application, before you can do that you need to understand the syntax of both PHP and MySQL. So we begin by giving you PHP and MySQL statements that you can actually try yourself. That way you can immediately do something with PHP and MySQL, and you will begin to get excited about them. Then, a bit later in the book, we show you good application and database design practices. By then you’ll have a solid grasp of the syntax you need, and can focus on learning the concepts.
We don’t cover every PHP and MySQL statement, function, or keyword.
While we could have put every single PHP and MySQL statement, function, and keyword in this book, we thought you’d prefer to have a reasonably liftable book that would teach you the most important statements, functions, and keywords. We give you the ones you need to know, the ones you’ll use 95 percent of the time. And when you’re done with this book, you’ll have the confidence to go look up that function you need to finish off that kick-ass application you just wrote.
We support PHP 5 and MySQL 5.0.
Because so many people still use PHP 4 or 5, we avoid any PHP 4, 5, or 6 specific code wherever possible. We suggest you use PHP 5 or 6 and MySQL 5 or 6 while learning the concepts in this book. In developing this book, we focused on PHP 5 and MySQL 5, while making sure our code was compatible with later versions.
You need a web server that supports PHP.
PHP has to be run through a web server to work correctly. You need Apache or some other web server installed on your local machine or a machine to which you have some access so that you can run MySQL commands on the data. Check out Appendixes ii and iii for instructions on how to install and extend PHP and MySQL.
We use MySQL.
While there’s Standard SQL language, in this book we focus on the particular syntax of MySQL. With only a few syntax changes, the code in this book should work with Oracle, MS SQL Server, PostgreSQL, DB2, and quite a few more Relational Database Management Systems (RDBMSs) out there. You’ll need to look up the particular PHP functions and syntax if you want to connect to these other RDBMSs. If we covered every variation in syntax for every command in the book, this book would have many more pages. We like trees, so we’re focusing on MySQL.