PHP and MySQL for Dummies

PHP and MySQL for Dummies

2.0 16
by Janet Valade
     
 

View All Available Formats & Editions

You need to develop an interactive Web site in a hurry! Your boss just put you in charge of your company’s online catalog. And you don’t have a clue about how to develop a Web database application. Don’t panic, the Dynamic Duo,” PHP and MySQL, are here to save the day. MySQL is a fast, easy-to-use, open-source relational database management

Overview

You need to develop an interactive Web site in a hurry! Your boss just put you in charge of your company’s online catalog. And you don’t have a clue about how to develop a Web database application. Don’t panic, the Dynamic Duo,” PHP and MySQL, are here to save the day. MySQL is a fast, easy-to-use, open-source relational database management system that runs on most operating systems. PHP is a fast, easy-to-use, free scripting language designed for use on the Web that interacts with just about every type of database management system. Together, PHP and SQL have spelled relief for thousands of reluctant Web database developers just like you.

PHP and MySQL For Dummies fills you in on how to develop Web database applications using the Dynamic Duo — and no programming or database experience required! With this friendly reference as your guide, you’ll:

  • Build and use a MySQL database
  • Add PHP to HTML files
  • Use all the features of the PHP language
  • Use HTML forms to collect information from users
  • Show information from a database in a Web page
  • Store information in a database

In plain English, expert Janet Valade explains PHP and MySQL and shows you how to access and get started with them. And with the help of two complete sample applications, she walks you through the entire Web database application development process. Topics covered in detail include:

  • Creating and changing MySQL databases and moving data in and out of them
  • Writing PHP programs that enable your Web pages to insert, update, or remove information from a MySQL database
  • Organizing PHP programs into a functioning application that interacts with MySQL databases
  • Common traps to avoid when developing Web database applications and fixes for common problems

The bonus CD-ROM features:

  • PHP
  • MySQL
  • Apache Web server
  • Sample applications and code from the book
Ready to take your site to a bold new level of interactivity? PHP and MySQL For Dummies shows you how.

Editorial Reviews

bn.com
The Barnes & Noble Review
For folks who need powerful web database applications but don’t have money to burn, PHP and MySQL go together like strawberries and cream. If all you know about web databases is that you need one, read this book.

It takes you every step of the way: setting up PHP 5 and MySQL 4; building your database; protecting your data (and working around MySQL security issues); creating queries; and handling the other tasks web databases commonly need to perform.

You’ll also walk through building two complete applications. (All the code’s been updated for the latest versions of PHP and MySQL. That’s essential, since important MySQL default settings have changed.) Bottom line: This book makes web databases downright doable. 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.

Product Details

ISBN-13:
9780764516504
Publisher:
Wiley
Publication date:
04/29/2002
Series:
For Dummies Series
Edition description:
Older Edition
Pages:
408
Product dimensions:
7.38(w) x 9.18(h) x 0.88(d)

Read an Excerpt

PHP and MySQL for Dummies with CDROM


By Janet Valade

John Wiley & Sons

ISBN: 0-7645-1650-7


Chapter One

Introduction to PHP and MySQL

In This Chapter

* Finding out what a Web database application is

* Taking a look at PHP

* Discovering how MySQL works

* Finding out how PHP and MySQL work together

So you need to develop an interactive Web site. Perhaps your boss just put you in charge of the company's online product catalog. Or you want to develop your own Web business. Or your sister wants to sell her paintings online. Or you volunteered to put up a Web site open only to members of your circus acrobats' association. Whatever your motivation may be, you can see that the application needs to store information (for instance, information about products, information about paintings, member passwords), thus requiring a database. You can also see that the application needs to interact dynamically with the user (for instance, the user selects a product to view, the user enters membership information). This type of Web site is called a Web database application.

You have created static Web pages before, using HTML, but creating an interactive Web site is a new challenge, as is designing a database. You asked three computer gurus you know what you should do. They said a lot of things you didn't understand, but among the technical jargon, you heard "quick" and "easy" and "free" mentioned in the same sentence as PHP and MySQL. Now you want to know moreabout using PHP and MySQL to develop the Web site you need.

PHP and MySQL work together very well. It's a dynamic partnership. In this chapter, you find out the advantages of each, how each one works, and how they work together to produce a dynamic Web database application.

What Is a Web Database Application?

An application is a program or a group of programs designed for use by an end user (for example, customers, members, circus acrobats, and so on). If the end user interacts with the application using a Web browser, the application is a Web-based or Web application. If the Web application requires the long-term storage of information, using a database, it is a Web database application. This book provides you with the information you need to develop a Web database application that can be accessed using Web browsers such as Internet Explorer and Netscape.

A Web database application is designed to help a user accomplish a task. It can be a simple application that displays information in a browser window (for example, it displays current job openings when the user selects a job title) or a complicated program with extended functionality (for example, the book-ordering application at Amazon or the bidding application at eBay).

Not surprisingly, a Web database application consists of an application and a database - just two pieces:

  •   The database is the long-term memory of your Web database application. The application can't fulfill its purpose without the database. However, the database alone is not enough.

  •   The application piece is the program or group of programs that perform the tasks. Programs create the display that the user sees in the browser window; they make your application interactive by accepting and processing information the user typed in the browser window; and they store information in the database and get information out of the database. The database is useless unless you can move data in and out.

    The Web pages you have previously created using HTML alone are static, meaning the user can't interact with the Web page. All users see the same Web page. Dynamic Web pages, on the other hand, allow the user to interact with the Web page. Different users might see different Web pages. For instance, one user looking at a furniture store's online product catalog might choose to view information about the sofas, whereas another user might choose to view information about coffee tables. To create dynamic Web pages, you must use another language, in addition to HTML.

    One language widely used to make Web pages dynamic is JavaScript. JavaScript is useful for several purposes, such as mouseovers (for example, to highlight a navigation button when the user moves the mouse pointer over it) or accepting and validating information that users type into a Web form. However, it is not useful for interacting with a database. You would not use JavaScript to move the information from the Web form into a database. PHP is a language that is particularly well suited to interacting with databases. PHP can accept and validate the information that users type into a Web form and can also move the information into a database. The programs in this book are written using PHP.

    The database

    The core of a Web database application is the database, the long-term memory that stores information for the application. A database is an electronic file cabinet that stores information in an organized manner so that you can find it when you need it. After all, storing information is pointless if you can't find it. A database can be small, with a simple structure - for example, a database containing the titles and authors' names of all the books you own. Or a database can be huge, with an extremely complex structure - such as the database Amazon must have to hold all its information.

    The information you store in the database comes in many varieties. A company's online catalog requires a database to store information about all the company's products. A membership Web site requires a database to store information about members. An employment Web site requires a database (or perhaps two databases) to store information about job openings and information from resumes. The information you plan to store may be similar to information that is stored by Web sites all over the Internet - or information that is unique to your application.

    Technically, the term database refers to the file or group of files that holds the actual data. The data is accessed using a set of programs called a Database Management System (DBMS). Almost all DBMSs these days are Relational Database Management Systems (RDBMSs), in which data is organized and stored in a set of related tables.

    In this book, MySQL is the RDBMS used because it is particularly well suited for Web sites. MySQL and its advantages are discussed in the section, "MySQL, My Database," later in this chapter. You can find out about how to organize and design a MySQL database in Chapter 3.

    The application: Moving data in and out of the database

    For the database to be useful, you need to be able to move data into and out of it. Programs are your tools for this. Programs interact with the database to store and retrieve data. A program connects to the database and makes a request: "Take this data and store it in the specified location." Another program makes the request: "Find the specified data and give it to me." The application programs that interact with the database run when the user interacts with the Web page. For instance, when the user clicks the Submit button after filling in a Web form, a program processes the information in the form and stores it in a database.

    MySQL, My Database

    MySQL is a fast, easy-to-use RDBMS used for databases on many Web sites. Speed was the developers' main focus from the beginning. In the interest of speed, they made the decision to offer fewer features than their major competitors (for instance, Oracle and Sybase). However, even though MySQL is less full-featured than its commercial competitors, it has all the features needed by the large majority of database developers. It is easier to install and use than its commercial competitors, and the difference in price is strongly in MySQL's favor.

    MySQL is developed, marketed, and supported by MySQL AB, a Swedish company. The company licenses it two ways:

  •   Open source software: MySQL is available via the GNU General Public License (GPL) for no charge. Anyone who can meet the requirements of the GPL can use the software for free. If you're using MySQL as a database on a Web site (the subject of this book), you can use MySQL for free, even if you're making money with your Web site.

  •   Commercial license: MySQL is available with a commercial license for those who prefer it to the GPL. If a developer wants to use MySQL as part of a new software product and wants to sell the new product, rather than release it under the GPL, the developer needs to purchase a commercial license. The fee is very reasonable. Finding technical support for MySQL is not a problem. You can join one of several e-mail discussion lists offered on the MySQL Web site at mysql. com. You can even search the e-mail list archives, which contain a large knowledge base of MySQL questions and answers. If you're more comfortable getting commercial support, MySQL AB offers technical support contracts - five support levels, ranging from direct e-mail support to phone support, at five price levels.

    Advantages of MySQL

    MySQL is a popular database with Web developers. Its speed and small size make it ideal for a Web site. Add to that the fact that it's open source, which means free, and you have the foundation of its popularity. Here is a rundown of some of its advantages:

  •   It's fast: The main goal of the folks who developed MySQL was speed. Consequently, the software was designed from the beginning with speed in mind.

  •   It's inexpensive: MySQL is free under the open source GPL license, and the fee for a commercial license is very reasonable.

  •   It's easy to use: You can build and interact with a MySQL database using a few simple statements in the SQL language, the standard language for communicating with RDBMSs. Check out Chapter 4 for the lowdown on the SQL language.

  •   It can run on many operating systems: MySQL runs on a wide variety of operating systems - Windows, Linux, Mac OS, most varieties of Unix (including Solaris, AIX, and DEC Unix), FreeBSD, OS/2, Irix, and others.

  •   Technical support is widely available: A large base of users provides free support via mailing lists. The MySQL developers also participate in the e-mail lists. You can also purchase technical support from MySQL AB for a very small fee.

  •   It's secure: MySQL's flexible system of authorization allows some or all database privileges (for example, the privilege to create a database or delete data) to specific users or groups of users. Passwords are encrypted.

  •   It supports large databases: MySQL handles databases up to 50 million rows or more. The default file size limit for a table is 4GB (gigabytes), but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million terabytes.

  •   It's customizable: The open source GPL license allows programmers to modify the MySQL software to fit their own specific environments.

  •   It's memory-efficient: MySQL is written and thoroughly tested to prevent memory leaks.

    How MySQL works

    The MySQL software consists of the MySQL server, several utility programs that assist in the administration of MySQL databases, and some supporting software that the MySQL server needs, but that you don't need to know about. The heart of the system is the MySQL server.

    The MySQL server is the manager of the database system. It handles all your database instructions. For instance, if you want to create a new database, you send a message to the MySQL server that says "create a new database and call it newdata." The MySQL server then creates a subdirectory in its data directory, names the new subdirectory newdata, and puts the necessary files with the required format into the newdata subdirectory. In the same manner, to add data to that database, you send a message to the MySQL server, giving it the data and telling it where you want the data to be added. You find out how to write and send messages to MySQL in Part II of this book.

    Before you can pass instructions to the MySQL server, it must be running. The MySQL server is usually set up so that it starts when the computer starts and continues running all the time. This is the usual setup for a Web site. However, it's not necessary to set it up to start when the computer starts. If you need to, you can start it manually whenever you want to access a database. When it's running, the MySQL server listens continuously for messages that are directed to it.

    Communicating with the MySQL server

    All your interaction with the database is done by passing messages to the MySQL server. You can send messages to the MySQL server several ways, but this book focuses on sending messages using PHP. The PHP software has specific statements that you use to send instructions to the MySQL server.

    The MySQL server must be able to understand the instructions that you send it. You communicate using the Structured Query Language (SQL), a standard language understood by many RDBMSs. The MySQL server understands SQL. PHP does not understand SQL, but it doesn't need to. PHP just establishes a connection with the MySQL server and sends the SQL message over the connection. The MySQL server interprets the SQL message and follows the instructions. The MySQL server sends a return message, stating its status and what it did (or reporting an error if it was unable to understand or follow the instructions). For the lowdown on how to write and send SQL messages to MySQL, check out Part II of this book.

    PHP, a Data Mover

    PHP is a scripting language designed specifically for use on the Web. PHP is your tool for creating dynamic Web pages. As a special-purpose language, PHP does not need to include many of the features required in a general, all-purpose programming language. Consequently, it is much simpler than many languages, such as C or Java, and contains only the features that are most useful for Web sites.

    PHP stands for PHP: Hypertext Preprocessor. In its early development by a guy named Rasmus Lerdorf, it was called Personal Home Page tools. When it developed into a full-blown language, the name was changed to be more in line with its expanded functionality.

    The PHP language's syntax is similar to the syntax of C, so if you have experience with C, you will be comfortable with PHP. PHP is actually simpler than C because it doesn't use some of the more difficult concepts of C. PHP also doesn't include the low-level programming capabilities of C because PHP is designed to program Web sites and doesn't require those capabilities.

    PHP is particularly strong in its ability to interact with databases. PHP supports pretty much every database you've ever heard of (and some you haven't).

    Continues...


    Excerpted from PHP and MySQL for Dummies with CDROM by Janet Valade 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.

  • Meet the Author

    Janet Valade has been a Web designer and programmer, a systems analyst, a builder of e-commerce Web applications, and an instructor of various computer topics.

    Customer Reviews

    Average Review:

    Write a Review

    and post it to your social network

         

    Most Helpful Customer Reviews

    See all customer reviews >

    PHP and MySQL For Dummies 2.6 out of 5 based on 0 ratings. 23 reviews.
    Guest More than 1 year ago
    I began very interested and willing to spend time learning this language but found that the book did not give detailed information on many key words and crucial elements to the code.
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Anonymous More than 1 year ago
    Guest More than 1 year ago
    This book is perfect if you want to go from a novice to a beginner/intermediate. I started off with this book and found it extremely helpful. I then decided to move up to advanced PHP and continued my learning with another book (found in my recommended reading below)
    Guest More than 1 year ago
    I bought this book and was fairly pleased with what I read. It covered all the basics of PHP and MySQL, though not much more than that. Since it is a relatively short book, PHP is not taught very thoroughly. There is a lot of advanced but very useful information that this book leaves out. Nonetheless, it seemed to be good for beginners, though it is probably helpful to read some sections over a few times, as many important aspects are only discussed in brief as a result of the limited space in this book. Since I wish to work with some more advanced features PHP has to offer, this book is merely a stepping stone to my current purchase of PHP and MySQL Web Development, 2nd Edition. When I am done reading that, I will probably write a review for it as well.
    Guest More than 1 year ago
    I used to be out in the blue about PHP, knowing only Java Script and HTML (which is outdated). Anyway, being 14 this book taught me fast and easily how to use a database correctly and HTML. It also taught me how to develop locally, I had been using Brinkster. All my peers think I am a true pro because of this book, Thanks
    Guest More than 1 year ago
    I can say a few things. 1) It was worth the $25 I spent on the book. 2) I know a whole lot more about MySQL and PHP then I did before I opened this book. 3) If you are new to PHP and/or MySQL, I really suggest this book. 4) On the other hand... If you have PHP/MySQL experience, get a more in depth book.
    Guest More than 1 year ago
    Considering this books title, you would think it's for complete novices to PHP (like myself). It starts out nicely being very informative but then towards the middle and end it begins to spew out PHP info and gives very little detail as to what all the 'jibberish' does. I was dissapointed, I was hoping for something way more in-depth. The included CD-ROM is nice but when you're done reading the book and you realize you only know slightly more then the absolute nothing you did know when you first started reading, you'll want to use that cd as a coaster instead.
    Guest More than 1 year ago
    This book, as with most all of the for Dummies series is clear and concise. Step by step instrcutions written in plain English. I recommend this book for any wanting to get their feet wet with PHP and MySQL