PHP and MySQL Web Development, 4th Edition (Developer's Library Series) / Edition 4

Multimedia Set (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $16.36
Usually ships in 1-2 business days
(Save 70%)
Other sellers (Multimedia Set)
  • All (21) from $16.36   
  • New (9) from $30.76   
  • Used (12) from $16.36   

Overview

PHP and MySQL Web Development, Fourth Edition
The definitive guide to building database-drive Web applications with PHP and MySQL

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.

TABLE OF CONTENTS

Part I: Using PHP

1 PHP Crash Course
2 Storing and Retrieving Data
3 Using Arrays
4 String Manipulation and Regular Expressions
5 Reusing Code and Writing Functions
6 Object-Oriented PHP
7 Error and Exception Handling

Part II: Using MySQL
8 Designing Your Web Database
9 Creating Your Web Database
10 Working with Your MySQL Database
11 Accessing Your MySQL Database from the Web with PHP
12 Advanced MySQL Administration
13 Advanced MySQL Programming

Part III: E-Commerce and Security
14 Running an E-Commerce Site
15 E-commerce Security Issues
16 Web Application Security
17 Implementing Authentication with PHP and MySQL
18 Implementing Secure Transactions with PHP and MySQL

Part IV: Advanced PHP Techniques
19 Interacting with the File System and the Server
20 Using Network and Protocol Functions
21 Managing the Date and Time
22 Generating Images
23 Using Session Control in PHP
24 Other Useful Features

Part V: Building Practical PHP and MySQL Projects

25 Using PHP and MySQL for Large Projects
26 Debugging
27 Building User Authentication and Personalization
28 Building a Shopping Cart
29 Building a Web-Based Email Service
30 Building a Mailing List Manager
31 Building Web Forums
32 Generating Personalized PDF Documents
33 Connecting to Web Services with XML and SOAP
34 Building Web 2.0 Applications with Ajax

Part VI: Appendixes
Appendix A: Installing PHP and MySQL
Appendix B: Web Resources


An intermediate to advanced guide to PHP and MySQL, the free, open-sourced Web development products. Offers coverage of object-oriented Web programming, creating services using SSL and authentication, and other applications. The CD-ROM includes full versions of PHP, MySQL, and Apache for Windows and Linux/Unix systems, several graphics libraries, files containing the code listings in the book, and the entire book in PDF format.

Read More Show Less

Editorial Reviews

From Barnes & Noble
The Barnes & Noble Review
Thousands of web developers have found all the database help they need in PHP and MySQL Web Development. In their new Third Edition, Luke Welling and Laura Thomson update their classic to reflect new enhancements ranging from PHP5’s new object model to MySQL 5’s long-awaited stored procedures.

As before, you’ll find loads of practical sample code (all of it on the accompanying CD-ROM). The authors begin with a crash course on PHP itself: basic syntax, storing and retrieving data from flat file databases, using arrays; working with strings and regular expressions; functions; code reuse; and finally, object-oriented PHP.

One crucial PHP5 enhancement is exception handling: a unified, extensible, object-oriented solution for handling errors. Welling and Thompson cover PHP5 error handling in detail, from basic concepts and control structures through user-defined exceptions.

Next, you’ll master MySQL from the web developer’s point of view. Welling and Thompson introduce mysqli, PHP5’s new library for connecting with MySQL with either object-oriented or procedural syntax. Along the way, you’ll learn how to use MySQL's privilege system to secure your databases more effectively, and how to address the performance issues that arise in web database applications.

You'll find chapter-length coverage of networking, session control, interactions with filesystems and servers, managing dates and times, generating images, debugging, and more. The book’s highlight: seven start-to-finish projects, ranging from content management to email, generating on-the-fly PDFs to connecting with web services. Follow along with these case studies, and you should be ready to write just about anything. Bill Camarda

Bill Camarda is a consultant, writer, and web/multimedia content developer. His 15 books include Special Edition Using Word 2003 and Upgrading & Fixing Networks for Dummies, Second Edition.

From the Publisher
“This book by Welling & Thomson is the only one which I have found to be indispensable.The writing is clear and straightforward but never wastes my time.The book is extremely well laid out.The chapters are the right length and chapter titles quickly take you where you want to go.”
—Wright Sullivan, President,A&E
Engineering, Inc., Greer South Carolina

“There are several good introductory books on PHP, but Welling & Thomson is an excellent handbook for those who wish to build up complex and reliable systems. It’s obvious that the authors have a strong background in the development of professional applications and they teach not only the language itself, but also how to use it with good software engineering practices.”
—Javier Garcia, senior telecom engineer,
Telefonica R&D Labs, Madrid

“This book rocks! I am an experienced programmer, so I didn’t need a lot of help with PHP syntax; after all, it’s very close to C/C++. I don’t know a thing about databases, though, so when I wanted to develop a book review engine (among other projects) I wanted a solid reference to using MySQL with PHP. I have O’Reilly’s mSQL and MySQL book, and it’s probably a better pure-SQL reference, but this book has earned a place on my reference shelf…Highly recommended.”
—Paul Robichaux

“The true PHP/MySQL bible, PHP and MySQL Web Development by Luke Welling and Laura Thomson, made me realize that programming and databases are now available to the commoners. Again, I know 1/10000th of what there is to know, and already I’m enthralled.”
—Tim Luoma,TnTLuoma.com

Booknews
Shows how to combine the PHP scripting language with the MySQL database to produce interactive web sites. The guide provides examples that demonstrate tasks such as authenticating users, constructing a shopping cart, generating PDF documents and images dynamically, sending and managing email, facilitating user discussions, and managing content. Significant attention is paid to the importance of security. The CD-ROM contains PHP 4, MySQL, and Apache source code and binaries. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780672329166
  • Publisher: Addison-Wesley
  • Publication date: 10/15/2008
  • Series: Developer's Library Series
  • Edition description: Book with CD
  • Edition number: 4
  • Pages: 968
  • Sales rank: 129,694
  • Product dimensions: 7.00 (w) x 8.90 (h) x 2.20 (d)

Meet the Author

Lead Authors


Laura Thomson is a senior software engineer at Mozilla Corporation. She was formerly a principal at both OmniTI and Tangled Web Design, and she has worked for RMIT University and the Boston Consulting Group. She holds a Bachelor of Applied Science (Computer Science) degree and a Bachelor of Engineering (Computer Systems Engineering) degree with honors.

Luke Welling is a web architect at OmniTI and regularly speaks on open source and web development topics at conferences such as OSCON, ZendCon, MySQLUC, PHPCon, OSDC, and LinuxTag. Prior to joining OmniTI, he worked for the web analytics company Hitwise.com, at the database vendor MySQL AB, and as an independent consultant at Tangled Web Design. He has taught computer science at RMIT University in Melbourne, Australia, and holds a Bachelor of Applied Science (Computer Science) degree.


Contributing Authors


Julie C. Meloni has been developing web-based applications since the Web first saw the light of day and remembers the excitement surrounding the first GUI web browser. She has authored numerous books and articles on web-based programming languages and database topics, including the bestselling Sams Teach Yourself PHP, MySQL and Apache All in One.


Adam DeFields is a consultant specializing in web application development, project management, and instructional design. He lives in Grand Rapids, Michigan where he runs Emanation Systems, LLC, a company he founded in 2002. He has been involved with web development projects using several different technologies, but has developed a strong preference toward PHP/MySQL-based projects.


Marc Wandschneider is a freelance software developer, author, and speaker who travels the globe working on interesting projects. In recent years, a lot of his attention has been focused on writing robust and scalable web applications, and in 2005 he wrote a book called Core Web Application Programming with PHP and MySQL. He was was previously the main developer of the SWiK open source community site.

Read More Show Less

Read an Excerpt

Chapter 3: Using Arrays

This chapter shows you how to use an important programming construct—arrays. The variables that we looked at in the previous chapters are scalar variables, which store a single value. An array is a variable that stores a set or sequence of values. One array can have many elements. Each element can hold a single value, such as text or numbers, or another array. An array containing other arrays is known as a multidimensional array.

PHP supports both numerically indexed and associative arrays. You will probably be familiar with numerically indexed arrays if you've used a programming language, but unless you use PHP or Perl, you might not have seen associative arrays before. Associative arrays let you use more useful values as the index. Rather than each element having a numeric index, they can have words or other meaningful information.

We will continue developing the Bob's Auto parts example using arrays to work more easily with repetitive information such as customer orders. Likewise, we will write shorter, tidier code to do some of the things we did with files in the previous chapter.

Key topics covered in this chapter include

  • What is an array?

  • Numerically indexed arrays

  • Associative arrays

  • Multidimensional arrays

  • Sorting arrays

  • Further reading

What Is an Array?

We looked at scalar variables in Chapter 1, "PHP Crash Course." A scalar variable is a named location in which to store a value; similarly, an array is a named place to store a set of values, thereby allowing you to group common scalars.

Bob's product list will be the array for our example. In Figure 3.1, you can see a list of three products stored in an array format and one variable, called $products, which stores the three values. (We'll look at how to create a variable like this in a minute.)

Figure 3.1
Bob's products can be stored in an array.

After we have the information as an array, we can do a number of useful things with it. Using the looping constructs from Chapter 1, we can save work by performing the same actions on each value in the array. The whole set of information can be moved around as a single unit. This way, with a single line of code, all the values can be passed to a function. For example, we might want to sort the products alphabetically. To achieve this, we could pass the entire array to PHP's sort() function.

The values stored in an array are called the array elements. Each array element has an associated index (also called a key) that is used to access the element.

Arrays in most programming languages have numerical indexes that typically start from zero or one. PHP supports this type of array.

PHP also supports associative arrays, which will be familiar to Perl programmers. Associative arrays can have almost anything as the array indices, but typically use strings.

We will begin by looking at numerically indexed arrays.

Numerically Indexed Arrays

These arrays are supported in most programming languages. In PHP, the indices start at zero by default, although you can alter this.

Initializing Numerically Indexed Arrays

To create the array shown in Figure 3.1, use the following line of PHP code:

$products = array( "Tires", "Oil", "Spark Plugs" );

This will create an array called products containing the three values given—"Tires", "Oil", and "Spark Plugs". Note that, like echo, array() is actually a language construct rather than a function.

Depending on the contents you need in your array, you might not need to manually initialize them as in the preceding example.

If you have the data you need in another array, you can simply copy one array to another using the = operator.

If you want an ascending sequence of numbers stored in an array, you can use the range() function to automatically create the array for you. The following line of code will create an array called numbers with elements ranging from 1 to 10:

$numbers = range(1,10);

If you have the information stored in file on disk, you can load the array contents directly from the file. We'll look at this later in this chapter under the heading "Loading Arrays from Files."

If you have the data for your array stored in a database, you can load the array contents directly from the database. This is covered in Chapter 10, "Accessing Your MySQL Database from the Web with PHP."

You can also use various functions to extract part of an array or to reorder an array. We'll look at some of these functions later in this chapter, under the heading "Other Array Manipulations."

Accessing Array Contents

To access the contents of a variable, use its name. If the variable is an array, access the contents using the variable name and a key or index. The key or index indicates which stored values we access. The index is placed in square brackets after the name.

Type $products[0], $products[1], and $products[2] to use the contents of the products array.

Element zero is the first element in the array. This is the same numbering scheme as used in C, C++, Java, and a number of other languages, but it might take some getting used to if you are not familiar with it.

As with other variables, array elements contents are changed by using the = operator. The following line will replace the first element in the array "Tires" with "Fuses".

$products[0] = "Fuses";

The following line could be used to add a new element—"Fuse"—to the end of the array, giving us a total of four elements:

$products[3] = "Fuses";

To display the contents, we could type

echo "$products[0] $products[1] $products[2] $products[3]";

Like other PHP variables, arrays do not need to be initialized or created in advance. They are automatically created the first time you use them.

The following code will create the same $products array:

$products[0] = "Tires";
$products[1] = "Oil";
$products[2] = "Spark Plugs";

If $products does not already exist, the first line will create a new array with just one element. The subsequent lines add values to the array.

Using Loops to Access the Array

Because the array is indexed by a sequence of numbers, we can use a for loop to more easily display the contents:

for ( $i = 0; $i<3; $i++ )
 echo "$products[$i] ";

This loop will give similar output to the preceding code, but will require less typing than manually writing code to work with each element in a large array. The ability to use a simple loop to access each element is a nice feature of numerically indexed arrays. Associative arrays are not quite so easy to loop through, but do allow indexes to be meaningful.

Associative Arrays

In the products array, we allowed PHP to give each item the default index. This meant that the first item we added became item 0, the second item 1, and so on. PHP also supports associative arrays. In an associative array, we can associate any key or index we want with each value.

Initializing an Associative Array

The following code creates an associative array with product names as keys and prices as values.

$prices = array( "Tires"=>100, "Oil"=>10, "Spark Plugs"=>4 );

Accessing the Array Elements

Again, we access the contents using the variable name and a key, so we can access the information we have stored in the prices array as $prices[ "Tires" ], $prices[ "Oil" ], and $prices[ "Spark Plugs" ].

Like numerically indexed arrays, associative arrays can be created and initialized one element at a time.

The following code will create the same $prices array. Rather than creating an array with three elements, this version creates an array with only one element, and then adds two more.

$prices = array( "Tires"=>100 );
$prices["Oil"] = 10;
$prices["Spark Plugs"] = 4;

Here is another slightly different, but equivalent piece of code. In this version, we do not explicitly create an array at all. The array is created for us when we add the first element to it.

$prices["Tires"] = 100;
$prices["Oil"] = 10;
$prices["Spark Plugs"] = 4;

Using Loops with each() and list()

Because the indices in this associative array are not numbers, we cannot use a simple counter in a for loop to work with the array. The following code lists the contents of our $prices array:

while( $element = each( $prices ) )
{
 echo $element[ "key" ];
 echo " - ";
 echo $element[ "value" ];
 echo "<br>";
}

The output of this script fragment is shown in Figure 3.2.

Figure 3.2
An each statement can be used to loop through arrays.

In Chapter 1, we looked at while loops and the echo statement. The preceding code uses the each() function, which we have not used before. This function returns the current element in an array and makes the next element the current one. Because we are calling each() within a while loop, it returns every element in the array in turn and stops when the end of the array is reached.

In this code, the variable $element is an array. When we call each(), it gives us an array with four values and the four indexes to the array locations. The locations key and 0 contain the key of the current element, and the locations value and 1 contain the value of the current element. Although it makes no difference which you choose, we have chosen to use the named locations, rather than the numbered ones.

There is a more elegant and more common way of doing the same thing. The function list() can be used to split an array into a number of values. We can separate two of the values that the each() function gives us like this...

Read More Show Less

Table of Contents


PHP and MySQL Web Development, Fourth Edition
Luke Welling and Laura Thomson
ISBN 0-672-32916-6
Addison-Wesley Professional
© 2009 Pearson Education, Inc.

TABLE OF CONTENTS

Introduction

Part I: Using PHP

1 PHP Crash Course
2 Storing and Retrieving Data
3 Using Arrays
4 String Manipulation and Regular Expressions
5 Reusing Code and Writing Functions
6 Object-Oriented PHP
7 Error and Exception Handling

Part II: Using MySQL
8 Designing Your Web Database
9 Creating Your Web Database
10 Working with Your MySQL Database
11 Accessing Your MySQL Database from the Web with PHP
12 Advanced MySQL Administration
13 Advanced MySQL Programming

Part III: E-Commerce and Security
14 Running an E-Commerce Site
15 E-commerce Security Issues
16 Web Application Security
17 Implementing Authentication with PHP and MySQL
18 Implementing Secure Transactions with PHP and MySQL

Part IV: Advanced PHP Techniques
19 Interacting with the File System and the Server
20 Using Network and Protocol Functions
21 Managing the Date and Time
22 Generating Images
23 Using Session Control in PHP
24 Other Useful Features

Part V: Building Practical PHP and MySQL Projects

25 Using PHP and MySQL for Large Projects
26 Debugging
27 Building User Authentication and Personalization
28 Building a Shopping Cart
29 Building a Web-Based Email Service
30 Building a Mailing List Manager
31 Building Web Forums
32 Generating Personalized PDF Documents
33 Connecting to Web Services with XML and SOAP
34 Building Web 2.0 Applications with Ajax

Part VI: Appendixes
Appendix A: Installing PHP and MySQL
Appendix B: Web Resources

Read More Show Less

Preface

Introduction

Welcome to PHP and MySQL Web Development. Within its pages, you will find distilled knowledge from our experiences using PHP and MySQL, two of the hottest web development tools around.

In this introduction, we cover

  • Why you should read this book
  • What you will be able to achieve using this book
  • What PHP and MySQL are and why they're great
  • What's changed in the latest versions of PHP and MySQL
  • How this book is organized

Let's get started.

Why You Should Read This Book

This book will teach you how to create interactive websites from the simplest order form through to complex, secure e-commerce sites or interactive Web 2.0 sites. What's more, you'll learn how to do it using open source technologies.

This book is aimed at readers who already know at least the basics of HTML and have done some programming in a modern programming language before but have not necessarily programmed for the Internet or used a relational database. If you are a beginning programmer, you should still find this book useful, but digesting it might take a little longer. We've tried not to leave out any basic concepts, but we do cover them at speed. The typical readers of this book want to master PHP and MySQL for the purpose of building a large or commercial website. You might already be working in another web development language; if so, this book should get you up to speed quickly.

We wrote the first edition of this book because we were tired of finding PHP books that were basically function references. These books are useful, but they don't help when your boss or client has said, "Go build me a shopping cart." In this book, we have done our best to make every example useful. You can use many of the code samples directly in your website, and you can use many others with only minor modifications.

What You Will Learn from This Book

Reading this book will enable you to build real-world, dynamic websites. If you've built websites using plain HTML, you realize the limitations of this approach. Static content from a pure HTML website is just that—static. It stays the same unless you physically update it. Your users can't interact with the site in any meaningful fashion.

Using a language such as PHP and a database such as MySQL allows you to make your sites dynamic: to have them be customizable and contain real-time information.

We have deliberately focused this book on real-world applications, even in the introductory chapters. We begin by looking at a simple online ordering system and work our way through the various parts of PHP and MySQL.

We then discuss aspects of electronic commerce and security as they relate to building a real-world website and show you how to implement these aspects in PHP and MySQL.

In the final part of this book, we describe how to approach real-world projects and take you through the design, planning, and building of the following projects:

  • User authentication and personalization
  • Shopping carts
  • Web-based email
  • Mailing list managers
  • Web forums
  • PDF document generation
  • Web services with XML and SOAP
  • Web 2.0 application with Ajax

You should be able to use any of these projects as is, or you can modify them to suit your needs. We chose them because we believe they represent some the most common web-based applications built by programmers. If your needs are different, this book should help you along the way to achieving your goals.

What Is PHP?

PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be executed each time the page is visited. Your PHP code is interpreted at the web server and generates HTML or other output that the visitor will see.

PHP was conceived in 1994 and was originally the work of one man, Rasmus Lerdorf. It was adopted by other talented people and has gone through four major rewrites to bring us the broad, mature product we see today. As of November 2007, it was installed on more than 21 million domains worldwide, and this number is growing rapidly. You can see the current number at http://www.php.net/usage.php.

PHP is an Open Source project, which means you have access to the source code and can use, alter, and redistribute it all without charge.

PHP originally stood for Personal Home Page but was changed in line with the GNU recursive naming convention (GNU = Gnu's Not Unix) and now stands for PHP Hypertext Preprocessor.

The current major version of PHP is 5. This version saw a complete rewrite of the underlying Zend engine and some major improvements to the language.

The home page for PHP is available at http://www.php.net.

The home page for Zend Technologies is http://www.zend.com.

What Is MySQL?

MySQL (pronounced My-Ess-Que-Ell) is a very fast, robust, relational database management system (RDBMS). A database enables you to efficiently store, search, sort, and retrieve data. The MySQL server controls access to your data to ensure that multiple users can work with it concurrently, to provide fast access to it, and to ensure that only authorized users can obtain access. Hence, MySQL is a multiuser, multithreaded server. It uses Structured Query Language (SQL), the standard database query language. MySQL has been publicly available since 1996 but has a development history going back to 1979. It is the world's most popular open source database and has won the Linux Journal Readers' Choice Award on a number of occasions.

MySQL is available under a dual licensing scheme. You can use it under an open source license (the GPL) free as long as you are willing to meet the terms of that license. If you want to distribute a non-GPL application including MySQL, you can buy a commercial license instead.

Why Use PHP and MySQL?

When setting out to build a website, you could use many different products.

You need to choose the following:

  • Hardware for the web server
  • An operating system
  • Web server software
  • A database management system
  • A programming or scripting language

Some of these choices are dependent on the others. For example, not all operating systems run on all hardware, not all web servers support all programming languages, and so on.

In this book, we do not pay much attention to hardware, operating systems, or web server software. We don't need to. One of the best features of both PHP and MySQL is that they work with any major operating system and many of the minor ones.

The majority of PHP code can be written to be portable between operating systems and web servers. There are some PHP functions that specifically relate to the filesystem that are operating system dependent, but these are clearly marked as such in the manual and in this book.

Whatever hardware, operating system, and web server you choose, we believe you should seriously consider using PHP and MySQL.

Some of PHP's Strengths

Some of PHP's main competitors are Perl, Microsoft ASP.NET, Ruby (on Rails or otherwise), JavaServer Pages (JSP), and ColdFusion.

In comparison to these products, PHP has many strengths, including the following:

  • Performance
  • Scalability
  • Interfaces to many different database systems
  • Built-in libraries for many common web tasks
  • Low cost
  • Ease of learning and use
  • Strong object-oriented support
  • Portability
  • Flexibility of development approach
  • Availability of source code
  • Availability of support and documentation

A more detailed discussion of these strengths follows.

Performance

PHP is very fast. Using a single inexpensive server, you can serve millions of hits per day. Benchmarks published by Zend Technologies (http://www.zend.com) show PHP outperforming its competition.

Scalability

PHP has what Rasmus Lerdorf frequently refers to as a "shared-nothing" architecture. This means that you can effectively and cheaply implement horizontal scaling with large numbers of commodity servers.

Database Integration

PHP has native connections available to many database systems. In addition to MySQL, you can directly connect to PostgreSQL, Oracle, dbm, FilePro, DB2, Hyperwave, Informix, InterBase, and Sybase databases, among others. PHP 5 also has a built-in SQL interface to a flat file, called SQLite.

Using the Open Database Connectivity Standard (ODBC), you can connect to any database that provides an ODBC driver. This includes Microsoft products and many others.

In addition to native libraries, PHP comes with a database access abstraction layer called PHP Database Objects (PDO), which allows consistent access and promotes secure coding practices.

Built-in Libraries

Because PHP was designed for use on the Web, it has many built-in functions for performing many useful web-related tasks. You can generate images on the fly, connect to web services and other network services, parse XML, send email, work with cookies, and generate PDF documents, all with just a few lines of code.

Cost

PHP is free. You can download the latest version at any time from http://www.php.net for no charge.

Ease of Learning PHP

The syntax of PHP is based on other programming languages, primarily C and Perl. If you already know C or Perl, or a C-like language such as C++ or Java, you will be productive using PHP almost immediately.

Object-Oriented Support

PHP version 5 has well-designed object-oriented features. If you learned to program in Java or C++, you will find the features (and generally the syntax) that you expect, such as inheritance, private and protected attributes and methods, abstract classes and methods, interfaces, constructors, and destructors. You will even find some less common features such as iterators. Some of this functionality was available in PHP versions 3 and 4, but the object-oriented support in version 5 is much more complete.

Portability

PHP is available for many different operating systems. You can write PHP code on free Unix-like operating systems such as Linux and FreeBSD, commercial Unix versions such as Solaris and IRIX, OS X, or on different versions of Microsoft Windows.

Well-written code will usually work without modification on a different system running PHP.

Flexibility of Development Approach

PHP allows you to implement simple tasks simply, and equally easily adapts to implementing large applications using a framework based on design patterns such as Model–View–Controller (MVC).

Source Code

You have access to PHP's source code. With PHP, unlike commercial, closed-source products, if you want to modify something or add to the language, you are free to do so.

You do not need to wait for the manufacturer to release patches. You also don't need to worry about the manufacturer going out of business or deciding to stop supporting a product.

Availability of Support and Documentation

Zend Technologies (http://www.zend.com), the company behind the engine that powers PHP, funds its PHP development by offering support and related software on a commercial basis.

The PHP documentation and community are mature and rich resources with a wealth of information to share.

What Is New in PHP 5?

You may have recently moved to PHP 5 from one of the PHP 4.x versions. As you would expect in a new major version, it has some significant changes. The Zend engine beneath PHP has been rewritten for this version. Major new features are as follows:

  • Better object-oriented support built around a completely new object model (see Chapter 6, "Object-Oriented PHP")
  • Exceptions for scalable, maintainable error handling (see Chapter 7, "Error and Exception Handling")
  • SimpleXML for easy handling of XML data (see Chapter 33, "Connecting to Web Services with XML and SOAP")

Other changes include moving some extensions out of the default PHP install and into the PECL library, improving streams support, and adding SQLite.

At the time of writing, PHP 5.2 was the current version, with PHP 5.3 on the near horizon. PHP 5.2 added a number of useful features including:

  • The new input filtering extension for security purposes
  • JSON extension for better JavaScript interoperability
  • File upload progress tracking
  • Better date and time handling
  • Many upgraded client libraries, performance improvements (including better memory management in the Zend Engine), and bug fixes

Key Features of PHP 5.3

You may have heard about a new major release of PHP, called PHP 6. At the time of this writing, PHP 6 is not in the release candidate stage, and hosting providers won't be installing it for mass use for quite some time. However, some of the key features planned in PHP 6 have been back-ported to PHP 5.3, which is a minor version release and closer to passing acceptance testing and thus installation by hosting providers (of course, if you are your own server's administrator, you can install any version you like).

Some of the new features in PHP 5.3 are listed below; additional information also appears throughout this book as appropriate:

  • The addition of namespaces; for more information see http://www.php.net/language.namespaces
  • The addition of the intl extension for application internationalization; for more information see http://www.php.net/manual/en/intro.intl.php
  • The addition of the phar extension for creating self-contained PHP application archives; for more information see http://www.php.net/book.phar
  • The addition of the fileinfo extension for enhanced ability to work with files; for more information see http://www.php.net/manual/en/book.fileinfo.php
  • The addition of the sqlite3 extension for working with the SQLite Embeddable SQL Database Engine; for more information see http://www.php.net/manual/en/class.sqlite3.php
  • The inclusion of support for the MySQLnd driver, a replacement for libmysql; for more information see http://forge.mysql.com/wiki/PHP_MYSQLND

While the list above contains some of the highly-touted features of PHP 5.3, the release also includes a significant number of bug fixes and maintenance performed on existing functionality, such as:

  • Removing support for any version of Windows older than Windows 2000 (such as Windows 98 and NT4)
  • Ensuring the PCRE, Reflection, and SPL extensions are always enabled
  • Adding a few date and time functions for ease of date calculation and manipulation
  • Improving the crypt(), hash(), and md5() functionality, as well as improving the OpenSSL extension
  • Improving php.ini administration and handling, including better error reporting
  • Continuing to fine-tune the Zend engine for better PHP runtime speed and memory usage

Some of MySQLs Strengths

MySQLs main competitors are PostgreSQL, Microsoft SQL Server, and Oracle.

MySQL has many strengths, including the following:

  • High performance
  • Low cost
  • Ease of configuration and learning
  • Portability
  • Availability of source code
  • Availability of support

A more detailed discussion of these strengths follows.

Performance

MySQL is undeniably fast. You can see the developers' benchmark page at http://web.mysql.com/whymysql/benchmarks. Many of these benchmarks show MySQL to be orders of magnitude faster than the competition. In 2002, eWeek published a benchmark comparing five databases powering a web application. The best result was a tie between MySQL and the much more expensive Oracle.

Low Cost

MySQL is available at no cost under an open source license or at low cost under a commercial license. You need a license if you want to redistribute MySQL as part of an application and do not want to license your application under an Open Source license. If you do not intend to distribute your application—typical for most web applications, or are working on free or open source Software, you do not need to buy a license.

Ease of Use

Most modern databases use SQL. If you have used another RDBMS, you should have no trouble adapting to this one. MySQL is also easier to set up than many similar products.

Portability

MySQL can be used on many different Unix systems as well as under Microsoft Windows.

Source Code

As with PHP, you can obtain and modify the source code for MySQL. This point is not important to most users most of the time, but it provides you with excellent peace of mind, ensuring future continuity and giving you options in an emergency.

Availability of Support

Not all open source products have a parent company offering support, training, consulting, and certification, but you can get all of these benefits from MySQL AB (http://www.mysql.com).

What Is New in MySQL 5?

Major changes introduced for MySQL 5 include

  • Views
  • Stored procedures (see Chapter 13, "Advanced MySQL Programming")
  • Basic trigger support
  • Cursor support

Other changes include more ANSI standard compliance and speed improvements.

If you are still using an early 4.x version or a 3.x version of the MySQL server, you should know that the following features were added to various versions from 4.0:

  • Subquery support
  • GIS types for storing geographical data
  • Improved support for internationalization
  • The transaction-safe storage engine InnoDB included as standard
  • The MySQL query cache, which greatly improves the speed of repetitive queries as often run by web applications

This book was written using MySQL 5.1 (Beta Community Edition). This version also added support for

  • Partitioning
  • Row based replication
  • Event scheduling
  • Logging to tables
  • Improvements to MySQL Cluster, information schema, backup processes, and many bug fixes

How Is This Book Organized?

This book is divided into five main parts:

Part I, "Using PHP," provides an overview of the main parts of the PHP language with examples. Each example is a real-world example used in building an e-commerce site rather than "toy" code. We kick off this section with Chapter 1, "PHP Crash Course." If you've already used PHP, you can whiz through this chapter. If you are new to PHP or new to programming, you might want to spend a little more time on it. Even if you are quite familiar with PHP but you are new to PHP 5, you will want to read Chapter 6, "Object-Oriented PHP," because the object-oriented functionality has changed significantly.

Part II, "Using MySQL," discusses the concepts and design involved in using relational database systems such as MySQL, using SQL, connecting your MySQL database to the world with PHP, and advanced MySQL topics, such as security and optimization.

Part III, "E-commerce and Security," covers some of the general issues involved in developing a website using any language. The most important of these issues is security. We then discuss how you can use PHP and MySQL to authenticate your users and securely gather, transmit, and store data.

Part IV, "Advanced PHP Techniques," offers detailed coverage of some of the major built-in functions in PHP. We have selected groups of functions that are likely to be useful when building a website. You will learn about interaction with the server, interaction with the network, image generation, date and time manipulation, and session variables.

Part V, "Building Practical PHP and MySQL Projects," is our favorite section. It deals with practical real-world issues such as managing large projects and debugging, and provides sample projects that demonstrate the power and versatility of PHP and MySQL.

Finally

We hope you enjoy this book and enjoy learning about PHP and MySQL as much as we did when we first began using these products. They are really a pleasure to use. Soon, you'll be able to join the many thousands of web developers who use these robust, powerful tools to easily build dynamic, real-time websites.

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Customer Reviews

Average Rating 3
( 26 )
Rating Distribution

5 Star

(9)

4 Star

(1)

3 Star

(4)

2 Star

(3)

1 Star

(9)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
See All Sort by: Showing 1 – 20 of 26 Customer Reviews
  • Posted December 23, 2009

    Great reference manual for PHP and MySQL

    I recently started devoping websites with PHP and MySQL. I read several training manuals that included tutorials but I needed a good reference manual. This book meets that need.

    2 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Posted February 16, 2009

    I Liked the Second Edition So Well I Bought the Fourth Edition

    I learned PHP and MySql scripting from the second edition of this book. I liked the second edition so well, I bought the fourth edition for the updated information. To date, it has been the most helpful of all the books in my library concerning this topic. This book consistently gives more detail on how to use more functions of PHP than any other book I have read. This book provides a very good reference for MySql for almost all common usages. I keep my copy of this handy by my computer and reference it often when writing script.

    2 out of 3 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Posted September 21, 2009

    This is a great resource

    I also relied on the second edition of this book to truly get started learning PHP and MySQL. It was easy reading for a novice programmer, but quickly helped me achieve a high level of competency. I've learned a lot since then, but plan to buy the fourth edition for a new employee we are going to train as a web developer.

    1 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 5, 2014

    I am giving one because your source code is not completed .

    I am giving one because your source code is not completed .

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted May 29, 2009

    No text was provided for this review.

  • Anonymous

    Posted October 24, 2008

    No text was provided for this review.

  • Anonymous

    Posted March 30, 2010

    No text was provided for this review.

  • Anonymous

    Posted October 19, 2008

    No text was provided for this review.

  • Anonymous

    Posted October 10, 2009

    No text was provided for this review.

  • Anonymous

    Posted October 12, 2009

    No text was provided for this review.

  • Anonymous

    Posted December 16, 2009

    No text was provided for this review.

  • Anonymous

    Posted July 28, 2009

    No text was provided for this review.

  • Anonymous

    Posted December 18, 2008

    No text was provided for this review.

  • Anonymous

    Posted December 25, 2009

    No text was provided for this review.

  • Anonymous

    Posted July 9, 2009

    No text was provided for this review.

  • Anonymous

    Posted February 1, 2009

    No text was provided for this review.

  • Anonymous

    Posted December 29, 2008

    No text was provided for this review.

  • Anonymous

    Posted January 30, 2010

    No text was provided for this review.

  • Anonymous

    Posted January 4, 2009

    No text was provided for this review.

  • Anonymous

    Posted October 19, 2009

    No text was provided for this review.

See All Sort by: Showing 1 – 20 of 26 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)