Hướng Dẫn Học PHP và MySQL: Từ Cơ Bản Đến Nâng Cao

Chuyên đề nghiên cứu Học PHP và MySQL Dễ Dàng: Từ Người Mới Đến Chuyên Gia, cập nhật xu hướng mới, giá trị tham khảo cao cho chuyên gia chuyên ngành

Trường đại học

SitePoint Pty.

Chuyên ngành

Web Development

Người đăng

Ẩn danh

Thể loại

book

2017

687
1
0

Phí lưu trữ

135 Point

Mục lục chi tiết

Preface

1. Chapter 1 Installation

1.1. Your Own Web Server

1.2. Server Setup 1: Manually Installing All the Software Components

1.3. Server Setup 2: Pre-packaged Installations

1.4. Server Setup 3: Virtual Servers

1.5. Your Own Virtual Server

1.6. Installation on Windows

1.7. Installation on macOS

1.8. Installation on Linux

1.9. Getting Started with Vagrant

2. Chapter 2 Introducing PHP

2.1. Basic Syntax and Statements

2.2. Variables, Operators, and Comments

2.3. User Interaction and Forms

2.4. Passing Variables in Links

2.5. Passing Variables in Forms

2.6. GET or POST?

2.7. Hiding the Seams

2.8. PHP Templates

2.9. Many Templates, One Controller

2.10. Bring on the Database

3. Chapter 3 Introducing MySQL

3.1. An Introduction to Databases

3.2. Using MySQL Workbench to Run SQL Queries

3.3. Structured Query Language

3.4. A Word of Warning

3.5. Viewing Stored Data

3.6. Modifying Stored Data

3.7. Deleting Stored Data

3.8. Let PHP Do the Typing

4. Chapter 4 Publishing MySQL Data on the Web

4.1. The Big Picture

4.2. Creating a MySQL User Account

4.3. Connecting to MySQL with PHP

4.4. A Crash Course in Object-oriented Programming

4.5. Configuring the Connection

4.6. Sending SQL Queries with PHP

4.7. Handling SELECT Result Sets

4.8. Inserting Data into the Database

4.9. Deleting Data from the Database

5. Chapter 5 Relational Database Design

5.1. Giving Credit Where Credit Is Due

5.2. Rule of Thumb: Keep Entities Separate

5.3. SELECT with Multiple Tables

5.4. Many-to-many Relationships

5.5. One for Many, and Many for One

6. Chapter 6 Structured PHP Programming

6.1. Include Files

6.2. Including HTML Content

6.3. Including PHP Code

6.4. Types of Includes

6.5. Custom Functions and Function Libraries

6.6. Breaking Up Your Code Into Reusable Functions

6.7. Using Functions to Replace Queries

6.8. Editing Jokes on the Website

6.9. The Best Way

7. Chapter 7 Improving the Insert and Update Functions

7.1. Improving the Update Function

7.2. Stripping the Trailing Comma

7.3. Improving the Insert Function

7.4. Displaying the Joke Date

7.5. Making Your Own Tools

7.6. Using These Functions

7.7. Repeated Code Is the Enemy

7.8. Creating a Page for Adding and Editing

8. Chapter 8 Objects and Classes

8.1. Time for Class

8.2. Public vs Private

8.3. Using the DatabaseTable Class

8.4. Updating the Controller to Use the Class

8.5. Creating a Controller Class

8.6. Single Entry Point

8.7. Keeping it DRY

8.8. Be Careful With Extract

9. Chapter 9 Creating an Extensible Framework

9.1. Make Things Generic

9.2. Thinking Ahead: User Registration

9.3. Make it OOP

9.4. Reusing Code on Different Websites

9.5. Generic or Project Specific?

9.6. Making EntryPoint Generic

9.7. Autoloading and Namespaces

9.8. Implement an Autoloader

9.9. Autoloading with PSR-4

9.10. A Note on Composer

9.11. And the REST

9.12. Enforcing Dependency Structure with Interfaces

9.13. Your Own Framework

10. Chapter 10 Allowing Users to Register Accounts

10.1. Validating Email Addresses

10.2. Preventing the Same Person from Registering Twice

10.3. Securely Storing Passwords

11. Chapter 11 Cookies, Sessions, and Access Control

11.1. Counting Visits with Sessions

11.2. Protected Pages

11.3. Interfaces and Return Types

11.4. Making Use of the Authentication Class

11.5. Login Error Message

11.6. Creating a Login Form

11.7. Assigning Added Jokes to the Logged-in User

11.8. The Sky’s the Limit

12. Chapter 12 MySQL Administration

12.1. Backing Up MySQL Databases

12.2. Database Backups Using MySQL Workbench

12.3. Database Backups Using mysqlpump

12.4. Incremental Backups Using Binary Logs

12.5. MySQL Access Control Tips

12.6. Host Name Issues

12.7. Foreign Keys

12.8. Better Safe than Sorry

12.9. Object Relational Mappers

12.10. Methods in Entity Classes

12.11. Using Entity Classes from the DatabaseTable Class

12.12. Using the Joke Class

12.13. Simplifying the List Controller Action

12.14. Assigning Jokes to Categories

12.15. Assigning Categories to Jokes

12.16. Displaying Jokes by Category

13. Chapter 13 Creating a Form to Assign Permissions

13.1. Edit Author Permissions

13.2. A Crash Course in Binary

13.3. Be Bit-Wise

13.4. Back to PHP

13.5. Storing Bitwise Permissions in the Database

13.6. Join Table or Bitwise

13.7. Editing Others’ Jokes

14. Chapter 14 Content Formatting with Regular Expressions

14.1. String Replacement with Regular Expressions

14.2. Putting It All Together

14.3. Sorting, Limiting and Offsets

14.4. Pagination with LIMIT and OFFSET

14.5. Pagination in Categories

14.6. Achievement Unlocked: Ninja

Appendix A Using The Sample Code Repository

Appendix B Linux Troubleshooting

Tóm tắt

I. Giới thiệu về Học PHP và MySQL Dễ Dàng

Học PHP và MySQL là một hành trình thú vị cho những ai muốn phát triển ứng dụng web. PHP là một ngôn ngữ lập trình phổ biến, trong khi MySQL là hệ quản trị cơ sở dữ liệu mạnh mẽ. Bài viết này sẽ giúp người mới bắt đầu hiểu rõ hơn về cách học và ứng dụng hai công nghệ này.

1.1. Tại sao nên học PHP và MySQL

PHP và MySQL là nền tảng cho nhiều trang web hiện đại. Việc nắm vững chúng giúp phát triển ứng dụng web hiệu quả và nhanh chóng.

1.2. Lợi ích của việc học lập trình web

Học lập trình web mở ra nhiều cơ hội nghề nghiệp. Kỹ năng này không chỉ giúp tạo ra trang web mà còn nâng cao khả năng giải quyết vấn đề.

II. Những Thách Thức Khi Học PHP và MySQL

Mặc dù PHP và MySQL rất hữu ích, nhưng việc học chúng cũng không hề dễ dàng. Người học thường gặp phải nhiều khó khăn trong việc nắm bắt cú pháp và cách thức hoạt động của chúng.

2.1. Khó khăn trong việc nắm bắt cú pháp PHP

Cú pháp của PHP có thể gây nhầm lẫn cho người mới. Việc hiểu rõ các biến, hàm và cấu trúc điều kiện là rất quan trọng.

2.2. Thách thức trong việc quản lý cơ sở dữ liệu MySQL

Quản lý cơ sở dữ liệu yêu cầu kiến thức về SQL. Người học cần phải hiểu cách tạo, sửa đổi và truy vấn dữ liệu một cách hiệu quả.

III. Phương Pháp Học PHP và MySQL Hiệu Quả

Để học PHP và MySQL hiệu quả, người học cần có phương pháp học tập rõ ràng. Việc thực hành thường xuyên và tham gia vào các dự án thực tế là rất cần thiết.

3.1. Thực hành qua các dự án nhỏ

Thực hành qua các dự án nhỏ giúp củng cố kiến thức. Người học có thể bắt đầu với các ứng dụng đơn giản như blog hoặc hệ thống quản lý dữ liệu.

3.2. Sử dụng tài liệu và khóa học trực tuyến

Tài liệu và khóa học trực tuyến cung cấp kiến thức từ cơ bản đến nâng cao. Nguồn tài liệu phong phú giúp người học dễ dàng tiếp cận.

IV. Ứng Dụng Thực Tiễn của PHP và MySQL

PHP và MySQL được sử dụng rộng rãi trong phát triển ứng dụng web. Nhiều trang web lớn như Facebook và WordPress đều sử dụng công nghệ này.

4.1. Xây dựng hệ thống quản lý nội dung

Hệ thống quản lý nội dung (CMS) là một ứng dụng phổ biến. PHP và MySQL giúp quản lý nội dung một cách hiệu quả và dễ dàng.

4.2. Phát triển ứng dụng thương mại điện tử

Nhiều trang thương mại điện tử sử dụng PHP và MySQL để quản lý sản phẩm và đơn hàng. Điều này giúp tối ưu hóa quy trình bán hàng.

V. Kết Luận và Tương Lai của Học PHP và MySQL

Học PHP và MySQL không chỉ là việc nắm vững ngôn ngữ lập trình mà còn là việc phát triển tư duy logic và khả năng giải quyết vấn đề. Tương lai của lập trình web sẽ còn phát triển mạnh mẽ với sự hỗ trợ của các công nghệ mới.

5.1. Xu hướng phát triển công nghệ web

Công nghệ web đang phát triển nhanh chóng. Việc nắm vững PHP và MySQL sẽ giúp người học dễ dàng thích ứng với các xu hướng mới.

5.2. Cơ hội nghề nghiệp trong lĩnh vực lập trình

Nhu cầu về lập trình viên PHP và MySQL ngày càng tăng. Người học có thể tìm thấy nhiều cơ hội việc làm hấp dẫn trong lĩnh vực này.

11/01/2025

Trích đoạn nội dung tài liệu

ALL CODE AVAILABLE TO DOWNLOAD THE EASIEST WAY TO LEARN PHP PHP & MySQL: Novice to Ninja, 6th Edition is a hands-on guide to learning all the tools, principles, and techniques needed to build a professional web application using PHP & MySQL. YOUR AUTHORS PHP & MYSQL: NOVICE TO NINJA PHP TOM Comprehensively updated to cover PHP 7 and modern best BUTLER practice, this highly practical and fun book covers everything from installing PHP and MySQL through to creating a complete online content management system. Tom is a web developer, a Ph.D student researching software best BY TOM BUTLER practices, and university lecturer from the UK with an interest in & KEVIN YANK programming best practices, • Install PHP & MySQL on Windows, Mac OS X, or Linux separation of concerns and a “less is more” approach to code. • Gain a thorough understanding of PHP syntax KEVIN NOVICE TO NINJA PHP & MYSQL: • Master database design principles and SQL YANK • Write robust, maintainable, best practice code • Build a working content management system (CMS) Before joining Culture Amp in 2015, • And much more! Kevin taught a generation of web developers during his time at SitePoint, starting with the first edition of the book that you now hold in your hands.

While there, he helped to launch success stories like 99designs and Flippa. More recently, he quizzed web developers on HTML, CSS and JavaScript by leading the team behind Sit the Test, and has spoken at tech conferences around the world. WEB DEVELOPMENT PRINT ISBN: 978-0-9943469-8-8 SITEPOINT BOOKS Advocate best practice techniques Lead you through practical examples Provide working code for your website BUTLER & YANK Make learning easy and fun USD $39.95 BUILD YOUR OWN POWERFUL WEB APPLICATIONS Visit us on the Web at sitepoint.com or for sales and support email books@sitepoint.com SIXTH EDITION i PHP & MySQL: Novice to Ninja, 6th Edition by Tom Butler and Kevin Yank Copyright © 2017 SitePoint Pty. Product Manager: Simon Mackie Technical Editor: Bruno Škvorc English Editor: Ralph Mason Cover Designer: Alex Walker Notice of Rights All rights reserved.

No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews. Notice of Liability The author and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty., nor its dealers or distributors will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein.

Trademark Notice Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark. Published by SitePoint Pty. 48 Cambridge Street Collingwood VIC Australia 3066 Web: www.com Email: books@sitepoint.com ISBN 978-0-9943469-8-8 (print) ISBN 978-0-9953827-8-7 (ebook) Printed and bound in the United States of America www.ir ii PHP & MySQL: Novice to Ninja, 6th Edition About Tom Butler Tom is a web developer, a Ph.D student researching software best practices, and university lecturer from the UK with an interest in programming best practices, separation of concerns and a “less is more” approach to code. About Kevin Yank Before joining Culture Amp in 2015, Kevin taught a generation of web developers during his time at SitePoint, starting with the first edition of the book that you now hold in your hands.

While there, he helped to launch success stories like 99designs and Flippa. More recently, he quizzed web developers on HTML, CSS and JavaScript by leading the team behind Sit the Test, and has spoken at tech conferences around the world. On weekends he performs improvised theatre with Impro Melbourne, which is a lot more like building websites than you might expect. About SitePoint SitePoint specializes in publishing fun, practical, and easy-to-understand content for web professionals.

Visit http://www.com/ to access our blogs, books, newsletters, articles, and community forums. You’ll find a stack of information on JavaScript, PHP, Ruby, mobile development, design, and more.ir Table of Contents iii Table of Contents Preface .xv Who Should Read This Book .xvi Programming Has Changed.xvi It Takes 10,000 Hours to Become an Expert .xvii Resist the Temptation to Skip Ahead .xviii The Concorde Fallacy .xviii You’re Not Learning PHP .xix Getting Braces and Semicolons in the Right Place Is the Easy Part. xx You Won’t Get Anything Done by Planning. xx Conventions Used.

xxiii Supplementary Materials.xxiv Chapter 1 Installation .1 Your Own Web Server. 3 Server Setup 1: Manually Installing All the Software Components. 4 Server Setup 2: Pre-packaged Installations. 5 Server Setup 3: Virtual Servers.ir iv PHP & MySQL: Novice to Ninja, 6th Edition Your Own Virtual Server.

8 Installation on Windows. 8 Installation on macOS. 8 Installation on Linux. 9 Getting Started with Vagrant.

9 Chapter 2 Introducing PHP.15 Basic Syntax and Statements.18 Variables, Operators, and Comments .45 User Interaction and Forms .52 Passing Variables in Links .53 Passing Variables in Forms .62 GET or POST? .66 Hiding the Seams .ir Table of Contents v PHP Templates .69 Many Templates, One Controller .73 Bring on the Database .77 Chapter 3 Introducing MySQL.79 An Introduction to Databases .80 Using MySQL Workbench to Run SQL Queries.87 Structured Query Language .98 A Word of Warning. 104 Viewing Stored Data. 105 Modifying Stored Data.110 Deleting Stored Data. 111 Let PHP Do the Typing .112 Chapter 4 Publishing MySQL Data on the Web .ir vi PHP & MySQL: Novice to Ninja, 6th Edition The Big Picture.114 Creating a MySQL User Account .116 Connecting to MySQL with PHP.

120 A Crash Course in Object-oriented Programming. 126 Configuring the Connection. 129 Sending SQL Queries with PHP. 134 Handling SELECT Result Sets.

149 Inserting Data into the Database. 161 Deleting Data from the Database. 182 Chapter 5 Relational Database Design .183 Giving Credit Where Credit Is Due. 184 Rule of Thumb: Keep Entities Separate.

187 SELECT with Multiple Tables. 199 Many-to-many Relationships. 203 One for Many, and Many for One. 207 Chapter 6 Structured PHP Programming .ir Table of Contents vii Include Files.

209 Including HTML Content. 210 Including PHP Code. 212 Types of Includes. 215 Custom Functions and Function Libraries.

220 Breaking Up Your Code Into Reusable Functions. 228 Using Functions to Replace Queries. 238 Editing Jokes on the Website. 244 The Best Way.

246 Chapter 7 Improving the Insert and Update Functions .247 Improving the Update Function. 247 Stripping the Trailing Comma. 252 Improving the Insert Function. 258 Displaying the Joke Date .ir viii PHP & MySQL: Novice to Ninja, 6th Edition Making Your Own Tools.

270 Using These Functions. 276 Repeated Code Is the Enemy. 280 Creating a Page for Adding and Editing. 293 Chapter 8 Objects and Classes .294 Time for Class.

295 Public vs Private. 315 Using the DatabaseTable Class. 318 Updating the Controller to Use the Class. 326 Creating a Controller Class.

327 Single Entry Point .ir Table of Contents ix Keeping it DRY. 346 Be Careful With Extract. 349 Chapter 9 Creating an Extensible Framework. 355 Make Things Generic.

358 Thinking Ahead: User Registration. 378 Make it OOP. 378 Reusing Code on Different Websites. 386 Generic or Project Specific?.

387 Making EntryPoint Generic. 389 Autoloading and Namespaces. 398 Implement an Autoloader .ir x PHP & MySQL: Novice to Ninja, 6th Edition Autoloading with PSR-4. 406 A Note on Composer.

409 And the REST. 410 Enforcing Dependency Structure with Interfaces. 419 Your Own Framework. 422 Chapter 10 Allowing Users to Register Accounts .423 Validating Email Addresses.

433 Preventing the Same Person from Registering Twice. 434 Securely Storing Passwords. 442 Chapter 11 Cookies, Sessions, and Access Control. 454 Counting Visits with Sessions .ir Table of Contents xi Protected Pages.

467 Interfaces and Return Types. 472 Making Use of the Authentication Class. 474 Login Error Message. 476 Creating a Login Form.

483 Assigning Added Jokes to the Logged-in User. 490 The Sky’s the Limit. 494 Chapter 12 MySQL Administration.496 Backing Up MySQL Databases. 497 Database Backups Using MySQL Workbench.

498 Database Backups Using mysqlpump. 500 Incremental Backups Using Binary Logs. 502 MySQL Access Control Tips. 506 Host Name Issues .ir xii PHP & MySQL: Novice to Ninja, 6th Edition Foreign Keys.

518 Better Safe than Sorry .521 Object Relational Mappers. 528 Methods in Entity Classes. 529 Using Entity Classes from the DatabaseTable Class. 540 Using the Joke Class.

545 Simplifying the List Controller Action. 558 Assigning Jokes to Categories. 560 Assigning Categories to Jokes. 574 Displaying Jokes by Category.ir Table of Contents xiii Creating a Form to Assign Permissions.

595 Edit Author Permissions. 600 A Crash Course in Binary. 602 Be Bit-Wise. 603 Back to PHP.

604 Storing Bitwise Permissions in the Database. 607 Join Table or Bitwise. 610 Editing Others’ Jokes. 614 Chapter 14 Content Formatting with Regular Expressions.

617 String Replacement with Regular Expressions .ir xiv PHP & MySQL: Novice to Ninja, 6th Edition Putting It All Together. 633 Sorting, Limiting and Offsets. 639 Pagination with LIMIT and OFFSET. 645 Pagination in Categories.

653 Achievement Unlocked: Ninja. 658 Appendix A Using The Sample Code Repository. 661 Appendix B Linux Troubleshooting .ir Preface xv Preface It was 1998, I was twelve, and my parents had just bought the family our first modern PC. It wasn’t long before I had figured out how to change the code for one of my favorite first-person shooter games—little things like making the rocket launcher fire a hundred rockets a second instead of one, then having it fire a hundred rockets in every direction … and promptly crashing the game.

I was hooked, and I’ve been programming ever since. The game was multiplayer. Other people had also discovered how to change the code, and the arms race quickly escalated. Someone would fire a hundred rockets at me.

I’d have a script ready that would instantly build a wall right in front of me to block them all. My opponent would spawn a dozen land mines underneath me. I’d turn off the gravity, then jump, soaring away from the impending explosion. Everyone could fly.

It got to the point where it was no longer fun. You’d enter a game and someone had written a script to teleport you to the other side of the map, kill you instantly and force you to respawn, repeating the process a dozen times a second. They’d freeze your controls too, of course. We discovered ways to block all this, but by the end it was a stalemate.

Whoever managed to enter the game first could take complete control of it, and no matter how good your scripts were, there was nothing you could do. It was fun while it lasted. That’s how I learned the basics of coding, and that the only limit is your own imagination and creativity. During that time, I’d also taught myself HTML, and had my own website where I shared some of my game hacking techniques and scripts.

No, the website is not still up. Yes, it was terrible, full of bad grammar and cheesy animations (which was the style at the time, I promise!).

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ

Bài viết "Hướng Dẫn Học PHP và MySQL: Từ Cơ Bản Đến Nâng Cao" của tác giả Tom Butler và Kevin Yank cung cấp một cái nhìn toàn diện về việc học lập trình với PHP và quản lý cơ sở dữ liệu bằng MySQL. Nội dung sách được thiết kế từ cơ bản đến nâng cao, giúp cả những người mới bắt đầu và những người đã có kinh nghiệm có thể tiếp cận và nâng cao kỹ năng lập trình của mình. Độc giả sẽ được hướng dẫn chi tiết qua các ví dụ thực tế, giúp họ có thể áp dụng ngay vào các dự án thực tế. Sách cũng nhấn mạnh tầm quan trọng của việc nắm vững các khái niệm cơ bản trước khi chuyển sang các kỹ thuật phức tạp hơn, từ đó xây dựng nền tảng vững chắc cho việc phát triển ứng dụng web.

Nếu bạn quan tâm đến các khía cạnh khác trong lĩnh vực công nghệ thông tin, bạn có thể tham khảo thêm bài viết "Tùy Biến Thuật Toán Mã Khối Cho Bộ Thư Viện OpenSSL", nơi khám phá các kỹ thuật bảo mật trong lập trình, hoặc "Cài đặt và thực nghiệm SQLCipher trên hệ điều hành Android cho luận văn thạc sĩ", giúp bạn hiểu rõ hơn về việc bảo mật dữ liệu trong các ứng dụng di động. Ngoài ra, bài viết "Khóa luận tốt nghiệp về xây dựng website bán đồ gia dụng trong công nghệ thông tin" cũng sẽ mang đến cho bạn những kiến thức hữu ích về phát triển website, một phần quan trọng trong việc áp dụng PHP và MySQL vào thực tế.