PHP and MySQL Web Development

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

PHP and MySQL are popular open-source technologies that are ideal for quickly developing database-driven Web applications. PHP is a powerful scripting language designed to enable developers to create highly featured Web applications quickly, and MySQL is a fast, reliable database that integrates well with PHP and is suited for dynamic Internet-based applications.

 

PHP and MySQL Web Development shows how to use these tools together to produce effective, interactive Web applications. It clearly describes the basics of the PHP language, explains how to set up and work with a MySQL database, and then shows how to use PHP to interact with the database and the server.

 

This practical, hands-on book includes numerous examples that demonstrate common tasks such as authenticating users, constructing a shopping cart, generating PDF documents and images dynamically, sending and managing email, facilitating user discussions, connecting to Web services using XML, and developing Web 2.0 applications with Ajax-based interactivity.

 

The fourth edition of PHP and MySQL Web Development has been thoroughly updated, revised, and expanded to cover developments in PHP 5 through version 5.3, such as namespaces and closures, as well as features introduced in MySQL 5.1.

 

 

Author(s): Luke Welling, Laura Thomson
Edition: 4
Publisher: Addison-Wesley Professional
Year: 2008

Language: English
Pages: 1009

Table of Contents......Page 11
Introduction......Page 40
I: Using PHP......Page 50
1 PHP Crash Course......Page 52
Creating a Sample Application: Bob’s Auto Parts......Page 53
Embedding PHP in HTML......Page 56
Adding Dynamic Content......Page 60
Accessing Form Variables......Page 62
Understanding Identifiers......Page 67
Examining Variable Types......Page 68
Understanding Variable Scope......Page 70
Using Operators......Page 71
Working Out the Form Totals......Page 80
Understanding Precedence and Associativity......Page 81
Using Variable Functions......Page 83
Making Decisions with Conditionals......Page 85
Repeating Actions Through Iteration......Page 90
Employing Alternative Control Structure Syntax......Page 95
Next......Page 96
Saving Data for Later......Page 98
Storing and Retrieving Bob’s Orders......Page 99
Opening a File......Page 100
Writing to a File......Page 106
Closing a File......Page 108
Reading from a File......Page 110
Using Other Useful File Functions......Page 115
Locking Files......Page 117
A Better Way: Database Management Systems......Page 118
Next......Page 119
What Is an Array?......Page 120
Numerically Indexed Arrays......Page 121
Arrays with Different Indices......Page 124
Array Operators......Page 126
Multidimensional Arrays......Page 127
Sorting Arrays......Page 131
Sorting Multidimensional Arrays......Page 132
Reordering Arrays......Page 135
Loading Arrays from Files......Page 137
Performing Other Array Manipulations......Page 141
Next......Page 145
Creating a Sample Application: Smart Form Mail......Page 146
Formatting Strings......Page 149
Joining and Splitting Strings with String Functions......Page 155
Comparing Strings......Page 158
Matching and Replacing Substrings with String Functions......Page 159
Introducing Regular Expressions......Page 162
Finding Substrings with Regular Expressions......Page 168
Splitting Strings with Regular Expressions......Page 169
Next......Page 170
The Advantages of Reusing Code......Page 172
Using require() and include()......Page 173
Using Functions in PHP......Page 182
Examining Basic Function Structure......Page 185
Using Parameters......Page 187
Understanding Scope......Page 189
Passing by Reference Versus Passing by Value......Page 192
Using the return Keyword......Page 193
Implementing Recursion......Page 195
Next......Page 197
6 Object-Oriented PHP......Page 198
Understanding Object-Oriented Concepts......Page 199
Creating Classes, Attributes, and Operations in PHP......Page 201
Using Class Attributes......Page 203
Controlling Access with private and public......Page 205
Calling Class Operations......Page 206
Implementing Inheritance in PHP......Page 207
Designing Classes......Page 213
Writing the Code for Your Class......Page 214
Understanding Advanced Object-Oriented Functionality in PHP......Page 222
Next......Page 230
Exception Handling Concepts......Page 232
The Exception Class......Page 234
User-Defined Exceptions......Page 235
Exceptions in Bob’s Auto Parts......Page 238
Exceptions and PHP’s Other Error Handling Mechanisms......Page 241
Next......Page 242
II: Using MySQL......Page 244
8 Designing Your Web Database......Page 246
Relational Database Concepts......Page 247
Designing Your Web Database......Page 250
Web Database Architecture......Page 255
Next......Page 257
9 Creating Your Web Database......Page 258
Using the MySQL Monitor......Page 259
Logging In to MySQL......Page 260
Creating Databases and Users......Page 261
Introducing MySQL’s Privilege System......Page 262
Setting Up a User for the Web......Page 267
Creating Database Tables......Page 268
Understanding MySQL Identifiers......Page 274
Choosing Column Data Types......Page 275
Next......Page 280
What Is SQL?......Page 282
Inserting Data into the Database......Page 283
Retrieving Data from the Database......Page 285
Altering Tables After Creation......Page 300
Dropping a Whole Database......Page 303
Next......Page 304
11 Accessing Your MySQL Database from the Web with PHP......Page 306
How Web Database Architectures Work......Page 307
Querying a Database from the Web......Page 310
Putting New Information in the Database......Page 315
Using Prepared Statements......Page 319
Using Other PHP-Database Interfaces......Page 321
Next......Page 324
Understanding the Privilege System in Detail......Page 326
Making Your MySQL Database Secure......Page 333
Getting More Information About Databases......Page 335
Optimizing Your Database......Page 343
Backing Up Your MySQL Database......Page 344
Implementing Replication......Page 345
Next......Page 348
The LOAD DATA INFILE Statement......Page 350
Storage Engines......Page 351
Transactions......Page 352
Foreign Keys......Page 354
Stored Procedures......Page 355
Next......Page 362
III: E-commerce and Security......Page 364
Considering the Types of Commercial Websites......Page 366
Understanding Risks and Threats......Page 375
Next......Page 378
15 E-commerce Security Issues......Page 380
Security Threats......Page 381
Creating a Security Policy......Page 388
Authentication Principles......Page 389
Encryption Basics......Page 390
Digital Certificates......Page 394
Secure Web Servers......Page 395
Firewalls......Page 396
Data Backups......Page 397
Next......Page 398
Strategies for Dealing with Security......Page 400
Identifying the Threats We Face......Page 402
Understanding Who We’re Dealing With......Page 404
Securing Your Code......Page 406
Securing Your Web Server and PHP......Page 417
Database Server Security......Page 422
Protecting the Network......Page 424
Computer and Operating System Security......Page 426
Disaster Planning......Page 427
Next......Page 429
Identifying Visitors......Page 430
Implementing Access Control......Page 431
Using Basic Authentication......Page 438
Using Basic Authentication in PHP......Page 439
Using Basic Authentication with Apache’s .htaccess Files......Page 441
Using mod_auth_mysql Authentication......Page 445
Next......Page 447
Providing Secure Transactions......Page 448
Using Secure Sockets Layer (SSL)......Page 452
Providing Secure Storage......Page 456
Using Encryption in PHP......Page 458
Further Reading......Page 466
Next......Page 467
IV: Advanced PHP Techniques......Page 468
Uploading Files......Page 470
Using Directory Functions......Page 478
Interacting with the File System......Page 482
Using Program Execution Functions......Page 486
Next......Page 489
Examining Available Protocols......Page 490
Using Data from Other Websites......Page 491
Using Network Lookup Functions......Page 494
Backing Up or Mirroring a File......Page 498
Next......Page 507
Getting the Date and Time from PHP......Page 508
Converting Between PHP and MySQL Date Formats......Page 515
Calculating Dates in PHP......Page 516
Calculating Dates in MySQL......Page 517
Using the Calendar Functions......Page 519
Next......Page 520
22 Generating Images......Page 522
Understanding Image Formats......Page 523
Creating Images......Page 525
Using Automatically Generated Images in Other Pages......Page 529
Using Text and Fonts to Create Images......Page 530
Drawing Figures and Graphing Data......Page 538
Further Reading......Page 546
Next......Page 547
Understanding Basic Session Functionality......Page 548
Implementing Simple Sessions......Page 551
Creating a Simple Session Example......Page 553
Configuring Session Control......Page 555
Implementing Authentication with Session Control......Page 556
Next......Page 563
Evaluating Strings: eval()......Page 564
Serializing Variables and Objects......Page 565
Getting Information About the PHP Environment......Page 567
Temporarily Altering the Runtime Environment......Page 568
Highlighting Source Code......Page 569
Using PHP on the Command Line......Page 570
Next......Page 571
V: Building Practical PHP and MySQL Projects......Page 572
25 Using PHP and MySQL for Large Projects......Page 574
Planning and Running a Web Application Project......Page 575
Reusing Code......Page 576
Writing Maintainable Code......Page 577
Implementing Version Control......Page 581
Documenting Your Projects......Page 583
Prototyping......Page 584
Optimizing Code......Page 585
Testing......Page 587
Next......Page 588
Programming Errors......Page 590
Variable Debugging Aid......Page 598
Error Reporting Levels......Page 601
Altering the Error Reporting Settings......Page 602
Triggering Your Own Errors......Page 603
Handling Errors Gracefully......Page 604
Next......Page 606
Solution Components......Page 608
Solution Overview......Page 610
Implementing the Database......Page 612
Implementing the Basic Site......Page 613
Implementing User Authentication......Page 616
Implementing Bookmark Storage and Retrieval......Page 635
Implementing Recommendations......Page 641
Next......Page 645
Solution Components......Page 646
Solution Overview......Page 648
Implementing the Database......Page 651
Implementing the Online Catalog......Page 654
Implementing the Shopping Cart......Page 662
Implementing Payment......Page 678
Implementing an Administration Interface......Page 680
Next......Page 689
Solution Components......Page 690
Solution Overview......Page 693
Setting Up the Database......Page 694
Examining the Script Architecture......Page 696
Logging In and Out......Page 702
Setting Up Accounts......Page 705
Reading Mail......Page 710
Sending Mail......Page 721
Next......Page 725
Solution Components......Page 726
Solution Overview......Page 728
Setting Up the Database......Page 731
Defining the Script Architecture......Page 733
Implementing Login......Page 741
Implementing User Functions......Page 747
Implementing Administrative Functions......Page 760
Next......Page 779
Understanding the Process......Page 780
Solution Components......Page 781
Solution Overview......Page 782
Designing the Database......Page 783
Viewing the Tree of Articles......Page 786
Viewing Individual Articles......Page 799
Adding New Articles......Page 801
Adding Extensions......Page 808
Next......Page 809
Project Overview......Page 810
Solution Components......Page 815
Solution Overview......Page 817
Handling Problems with Headers......Page 843
Next......Page 844
Project Overview: Working with XML and Web Services......Page 846
Solution Components......Page 852
Solution Overview......Page 854
Installing the Project Code......Page 892
Further Reading......Page 893
34 Building Web 2.0 Applications with Ajax......Page 894
What Is Ajax?......Page 895
Fundamental Ajax......Page 899
Adding Ajax Elements to Earlier Projects......Page 909
For More Information......Page 923
Appendixes......Page 926
A: Installing PHP and MySQL......Page 928
Installing Apache, PHP, and MySQL Under Unix......Page 929
Installing Apache, PHP, and MySQL Under Windows......Page 938
Installing PEAR......Page 944
Setting Up Other Configurations......Page 945
PHP Resources......Page 946
Apache Resources......Page 948
Web Development......Page 949
Index......Page 950
A......Page 951
B......Page 954
C......Page 955
D......Page 959
E......Page 963
F......Page 965
H......Page 973
I......Page 974
K......Page 976
L......Page 977
M......Page 978
N......Page 981
O......Page 982
P......Page 983
R......Page 989
S......Page 991
T......Page 998
U......Page 1001
V......Page 1003
W......Page 1004
Z......Page 1007