BN.com Gift Guide

Beginning PHP5

( 2 )

Overview

What is this book about?

Beginning PHP5 is a complete tutorial in PHP5's language features and functionality, beginning with the basics and building up to the design and construction of complex data-driven Web sites. Fully functioning applications are developed through the course of the book. Other features of the book include ...

See more details below
Other sellers (Paperback)
  • All (26) from $1.99   
  • New (6) from $28.60   
  • Used (20) from $1.99   
Sending request ...

Overview

What is this book about?

Beginning PHP5 is a complete tutorial in PHP5's language features and functionality, beginning with the basics and building up to the design and construction of complex data-driven Web sites. Fully functioning applications are developed through the course of the book. Other features of the book include installation guide and troubleshooting tips, introduction to relational databases, practical working examples and applications, and a detailed language reference.

Here are the new topics in this edition:

  • OOP
  • PEAR
  • GTK
  • MSI
  • CLI
  • SQLite
  • Error handling with try/catch
Read More Show Less

Product Details

  • ISBN-13: 9780764557835
  • Publisher: Wiley
  • Publication date: 5/24/2004
  • Edition number: 1
  • Pages: 888
  • Product dimensions: 7.45 (w) x 9.25 (h) x 1.96 (d)

Meet the Author

Dave W. Mercer has 15 years’ experience in industrial and process engineering, and systems analysis, and is CTO for a B2B, responsible for the development and deployment of online automated business services. His entire site hosting server, and the applications he builds for hosted clients are programmed in PHP using Postgres or MySQL as the database.

Allan Kent is a PHP programmer who runs his own company and is a co-author of Beginning PHP 4. Alan has been programming seriously for the past dozen years and, other than the single blemish when he achieved a diploma in Cobol programming is entirely self-taught.

Steven D. Nowicki is Director of Software development at The Content Project, a Santa Monica, California-based consulting firm currently developing a massive enterprise resource planning and contact management system comprising more than 300,000 lines of OOPHP code. He has a decade of experience in large-scale software development and system architecture on all major platforms.

David Mercer is a PHP programmer and contributed to Beginning PHP 4. He has a keen interest in all things open source ever since he managed to put together a working Beowulf cluster by nicking old computer parts from colleagues and assembling them under his desk. He has worked on Wrox open source titles about PHP, Perl, and Linux.

Dan Squier is a longtime contributor to the Wrox community and a PHP Programmer.

Wankyu Choi is an accomplished PHP programmer and lead author of Beginning PHP 4. He holds a Master’s degree in English/Korean interpretation and translation form the Graduate School of Translation & Interpretation.

Heow Eide-Goodman is a member of NYPHP and LispNYC who uses PHP in his day job to doWeb sites, services, and back-office transformations among SQL Server, Interbase/Firebird, and MySQL.

Edward Lecky-Thompson is the founder and director of Ashridge New Media, a professional new media technology consultancy based in Berkhamsted, just north of London, England. Self-described as “utterly obsessed with PHP,” Ed has more than six years’ experience in commercial software development and enterprise-level systems architecture across myriad platforms, with particularly strong exposure to PHP and Apache on Linux-based platforms.

Clark Morgan is an experienced programmer who creates and administers databases with Web sites using PHP and MySQL for Fusion Computing and Media.

Read More Show Less

Table of Contents

Introduction.

Chapter 1: Getting Up and Running.

Chapter 2: Writing Simple Programs.

Chapter 3: PHP, HTML, and State.

Chapter 4: Decisions, Loops, and Arrays.

Chapter 5: Robust and Healthy Code.

Chapter 6: Writing High-Quality Code.

Chapter 7: Files and Directories.

Chapter 8: XML.

Chapter 9: An Introduction to Databases and SQL.

Chapter 10: Retrieving Data from MySQL Using PHP.

Chapter 11: Using PHP to Manipulate Data in MySQL.

Chapter 12: An Introduction to Object-Oriented Programming.

Chapter 13: Working with UML and Classes.

Chapter 14: PEAR.

Chapter 15: PHP5 and E-Mail.

Chapter 16: Generating Graphics.

Chapter 17: Case Study: A PHP Logging Agent.

Appendix A: Answers.

Appendix B: PHP Functions Reference.

Appendix C: Using SQLite.

Appendix D: ODBC.

Appendix E: PHP CLI.

Appendix F: Configuring PHP5.

Index.

Read More Show Less

First Chapter

Beginning PHP5


By Dave W. Mercer Allan Kent Steven D. Nowicki David Mercer Dan Squier Wankyu Choi Heow Eide-Goodman Ed Lecky-Thompson Clark Morgan

John Wiley & Sons

ISBN: 0-7645-5783-1


Chapter One

Getting Up and Running

PHP, which stands for HyperText Preprocessor, is widely used for creating programmed features for Web sites because it is easy to learn and also because PHP syntax is drawn from other widely used languages, making it familiar to many programmers. In this chapter we present a very brief history of PHP, and then discuss the nature of PHP as it relates to the Web.

Before you can get into the nitty-gritty of programming with PHP5, you need a clear understanding of how PHP programs work across the Web, and that obviously implies knowledge of the Web protocol called HyperText Transfer Protocol (HTTP). HTTP is the language or format for communications from browser to Web server and back, and is therefore fundamental to many aspects of PHP. HTTP gets some coverage in this chapter, and quite a bit more in Chapter 3.

You'll see how to properly setup PHP on a Linux server, and on a Windows server as well. PHP programs run in conjunction with Web pages, which in turn run (or are distributed by) Web server software (such as Apache or IIS), which in turn run on top of an operating system (such as Linux or Windows). Although it's not strictly necessary to know everything about network operating systems to build good PHP programs, there are many aspects of PHP that are controlled or affected by the Web server. If you're unfamiliar with server computers, Web servers, and the like, don't worry. You'll soon see how they work, and look at the requirements and process of installing basic Web server software.

This chapter leads you through installing PHP on a Red Hat Linux machine running Apache, and through installing PHP on a Windows 2000 machine running IIS. Just pick the one that's right for you.

You'll also examine the contents of the PHP configuration file php.ini with you, and test your PHP installation.

Obviously there's a lot of work for you in this chapter, so let's get started.

The Roots of PHP

PHP is a programming language designed to work with HTML, but unlike HTML, PHP has data processing capabilities. If you are familiar with HTML, you know that it is not really a programming language, but more of a rendering language-that is, HTML enables you to write Web pages using code that creates a pleasing (hopefully) display of text, graphics, and links within a browser. Although there are a few helpful features of HTML (such as the capability to cause a form submission), for the most part HTML does nothing programmatically. For example, there are no HTML commands that enable you to add two numbers together, or access a database.

If you remember the Web back in the early '90s, you may recall that early Web pages were made from HTML code written as plain text source files. When you made a connection to a Web site with your browser, the Web server software sent these plain text HTML files to be processed and rendered into Web pages. Your browser actually did the rendering process (and still does, to be sure), but if you clicked View[right arrow]Page Source, you'd see the raw HTML code.

Javascript (and a few other almost unknown programming languages) improved the situation for Web designers in that it provided for programmatic functionality within Web pages. However, it was limited to programmatic functionality on the user's computer, not on the back-end (on the Web server), where all the really cool data processing and database access takes place. Practical Extraction and Reporting Language (PERL) was one of the first widely used languages for programming on the back-end, but has limitations of its own, such as an inability to be mixed in with HTML for easy in-page programming.

So where does PHP fit in with HTML? PHP began as PHP/FI, developed in 1995 by Rasmus Lerdorf from some Perl scripts he had created for tracking accesses to his online resume. Eventually, Rasmus wrote an implementation in C, released the source code to the public, and by the beginning of 1998 version 3.0 of PHP was released (written by Rasmus Lerdorf, Andi Gutmans, and Zeev Suraski), the first version that is very similar to the current releases of PHP.

The main goal of PHP is to enable users to easily develop dynamic Web pages. The difference between dynamic Web pages and static Web pages is that the content and structure of dynamic Web pages may change each time they are accessed (that's what the back-end programming is for) whereas the content and structure of static Web pages is fixed and does not change unless the designer manually changes them.

Unlike many other languages, PHP can be embedded directly into HTML, making it quite easy for those familiar with HTML to grasp how to add back-end, programmatic functionality to their Web pages. This single capability is one of the most important factors in PHP's usefulness, and thereby its popularity. But have no doubt that PHP is growing into a much more full-features language going well beyond the initial intentions of its authors. PHP intends to be the primary language for a great variety of online and offline applications, and PHP5 is showing every sign of doing just that.

And you shouldn't forget how well PHP works with HTTP (HyperText Transfer Protocol), the communications protocol (pre-agreed format for data communications) for Web. Whenever you click a link or enter a Web address into your browser, a request in HTTP format is sent to the Web server, which responds by sending back the Web page. If the Web page isn't found, you'll probably get the "404 Not Found" error. Sending back the correct page or sending an error if the page is not found are HTTP functions. We discuss HTTP thoroughly in Chapter 2 because several important aspects of PHP applications depend on HTTP.

Installing, Configuring, and Running PHP

Before you can write a PHP application that works with your Web pages, you need to have PHP installed and configured. Because you'll be writing a Web application, it's a given that you'll need a Web server and some Web pages (a short HTML primer is provided in Chapter 3, although it's assumed that you know or can easily pick up how to make basic Web pages). You'll also need to download, install, and configure PHP, so we provide complete instructions about how to do these things in the coming sections. Note that some configuration options for PHP are related to very specific application requirements (you don't need to worry about them unless you need them) so many of the options aren't discussed until you reach the appropriate chapter.

System Requirements

To run the code in this book you will need at least the following software:

Server software (an operating system such as Windows 2000 or Linux)

A PHP-compatible Web server (such as Apache or Internet Information Server (IIS)

PHP5 (get the download from php.net)

A relational database system (starting at Chapter 9, we use SQLite or MySQL)

A Web browser (such as IE, Mozilla, and so on)

A text editor, such as Notepad, Emacs, vi, BBEdit, and so on.

You shouldn't have to worry about hard drive space or RAM, unless you are working on a very old system, or one that is overloaded. PHP doesn't take up much room, and runs very efficiently.

You can run all of the software listed here on the same computer, for development purposes. If you have access to several networked computers, you may want to install all of your server software on one (typically either a UNIX or Windows NT/2000 computer), and use another networked computer as your client machine. For the purposes of this book, we will generally assume you are running all of the software on a single computer. This is the configuration used by most Web developers.

php.ini, the PHP Configuration File

There are two examples of PHP configuration files that come with PHP when you download it: php.ini-dist and php.ini-recommended. After you download and install PHP, there will be one file named php.ini strategically placed on your system, and each time PHP starts it will read this file and set itself up accordingly. The php.ini file can be written out by hand, but of course most of us just modify either the dist or recommended file to suit our needs, and then copy and rename it into the appropriate folder.

However, you should note the following lines in the top of the dist file:

; This is the default settings file for new PHP installations.

; By default, PHP installs itself with a configuration suitable for

; development purposes, and *NOT* for production purposes.

The settings in the dist file are used for nearly all of the examples in this book and we'll let you know whenever the configuration settings are changed. But you will want to use the recommended file when you complete your applications and copy them over to your production server, and you should be aware that you may need to rewrite your code a little bit to work properly with the recommended file's configuration settings. We'll discuss this more as we go along.

Setting Up a Test Machine

In this chapter, we'll walk through setting up PHP5 on a Red Hat Linux machine running the Apache Web server, as well as on a Windows 2000 machine running Internet Information Server (IIS). You can run PHP5 with many other operating systems and Web servers, so see the PHP5 documentation for installation and configuration on other servers. And there are a variety of installation methods you can use. For example, there is an automatic installer for the Windows version, whereas you can install the Linux version using RPMs (for some versions of Linux), and you can also download and compile the Linux versions from the original source code if you like. None of the installations are all that difficult if you follow procedures correctly, and the examples we provide are a good starting point for many of the installations available.

There are some third-party installers (often open-source and free) out there, if you want to look for them. For instance, you might try PHPTriad or Foxserv in Google.

Network Connections

If you don't already know, a computer doesn't need to be attached to the Internet, or even to a network, to run Web server software. If you install a Web server on a computer, it's always possible to access that Web server from a Web browser running on the same machine, even if it doesn't have a network card or modem. Of course, to download and install the software you need, you have to have access to an Internet connection. But you don't need it to be active just because you're running your Web server.

Once you have a Web server installed and running, you'll install PHP5 alongside it. There's some configuration required to tell the Web server how to run PHP programs, and we'll walk through that process before we start PHP. There is an automatic installer to be found with most distributions of PHP; we'll use a primarily manual process to illustrate what's happening during installation.

What if it goes wrong? The README and INSTALL files that are included in most PHP downloads, as well as the PHP manual at php.net/manual/, provide detailed information which may be more up-to-date than the information here, which covers the PHP5.0.2 release.

Where Do You Start?

There are two main installation paths from which to choose, and each simply depends on which operating system you're using:

Installing PHP5 with the Apache Web Server on Linux (we use Red Hat Fedora Linux)

Installing PHP5 with Microsoft Internet Information Server on Windows (we use Windows 2000)

PHP5 can be installed on a great variety of Web server/operating system combinations, including under Apache on Windows. The two systems we're using are the easiest to get working. If neither of them suits you, of course you can install whatever other configuration you want-you should still be able to run all of the examples in the book. Refer to the PHP5 manual for more general installation instructions.

Running PHP5

One of the basic choices to make when installing PHP5 with your Web server is whether to run it as a CGI binary or as a separate static or dynamic module. CGI (Common Gateway Interface) is a very useful way to run interpreters such as PHP5. Because of security risks (see the "Running as a CGI" section later in this chapter for more information), compiling PHP5 as a static or dynamic module is recommended under most circumstances. Our installations (on Linux and on Windows) load PHP as a separate SAPI (Server Application Programming Interface) module. On Windows, the ISAPI filter was used to run PHP as a SAPI module.

Although it is most common to run PHP in conjunction with a Web server, so that Web pages with a file extension such as .php are processed through the PHP interpreter before the finished page is sent back to the browser, there is also a command line utility that enables you to run PHP code from the command line. It is present from any of the installation types we demonstrate. You can find plenty of documentation about it on the PHP site (php.net).

Creating and running PHP Web applications in a satisfactory way implies that you are running (or have access to) a Web server upon which PHP is (or can be) installed, and that the installation has been tested and runs properly. It also implies that PHP has been (or can be) configured to support the needs of your PHP programs. There are a couple scenarios under which these requirements can be achieved:

You are running a desktop or server machine, operating system, and Web server compatible with PHP, and PHP has been installed and configured.

You are running a desktop or server machine connected to the Internet, with access to a Web hosting account supported by a Web server with which PHP has been installed and configured.

The vast majority of desktop machines run Windows 98, NT, 2000, 2003, and XP. In many cases you can get a free copy of Personal Web Server (PWS) and install it on a machine running one of these operating systems. PHP is compatible with PWS, so you can install and configure PHP on desktop machines running basic operating systems such as Windows 98. Server operating systems such as Windows NT, 2000, and 200, come with Internet Information Server (IIS). PHP is compatible with IIS, and you can install and configure PHP on these machines. Our Windows 2000 installation of PHP5 uses IIS as a Web server.

The majority of Web-hosting computers run some version of Linux, such as Debian, RedHat, FreeBSD, and so on. The Web server of choice for these machines is Apache. PHP is compatible with Linux and Apache, and you can install and configure PHP on these systems, but if you are not in charge of the Web-hosting computer (and many times you won't be) you'll probably have little control over the installation and configuration.

Continues...


Excerpted from Beginning PHP5 by Dave W. Mercer Allan Kent Steven D. Nowicki David Mercer Dan Squier Wankyu Choi Heow Eide-Goodman Ed Lecky-Thompson Clark Morgan Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Customer Reviews

Average Rating 3
( 2 )
Rating Distribution

5 Star

(1)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(1)

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
Sort by: Showing all of 2 Customer Reviews
  • Anonymous

    Posted November 6, 2004

    I found this book extremely useful.

    The PHP code in this book (which can be downloaded from the publisher's site in .zip or .rar files) can be used on a local machine as well as uploaded to your server and used in the real world. You may need to make modifications to the code to reflect the domain name, etc. of your particular server. With that out of the way, let me say that this book has been extremely useful to me (a beginner). Not only does it start with the fundamentals of PHP, including installation, it continues through many advanced areas of programming so that you do not need to rush out and buy another book to complete your project. It even covers some basic HTML integration for those that are new to that too. All in all, I have not seen any other book on PHP5 with the depth and ease-of-use of this one.

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

    Posted August 22, 2011

    No text was provided for this review.

Sort by: Showing all of 2 Customer Reviews

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