Chapter 8. The PHP API

PHP is a scripting language that lets you write Web pages containing embedded code that is executed whenever a page is accessed and that can generate dynamic content to be included as part of the output sent to a client's Web browser. This chapter describes how to use PHP to write Web-based applications that use MySQL. For a comparison of PHP with the C and Perl DBI APIs for MySQL programming, see Chapter 5, "Introduction to MySQL Programming."

The examples in this chapter draw on our sample database, samp_db, using the tables that we created for the grade-keeping project and for the Historical League in Chapter 1, "Introduction to MySQL and SQL." We'll cover PHP 3, although as I write PHP 4 is in beta testing and may be available by the time you read this. Compatibility with PHP 3 is one of the explicit design goals for PHP 4, so almost everything said here about PHP 3 should apply to PHP 4. A set of migration notes for PHP 4 describes changes from PHP 3. You should read those notes if you're using PHP 4.

This chapter was written under the assumption that you'll use PHP in conjunction with the Apache Web server. The MySQL C client library and header files must be installed as well; those files are needed when you build PHP, or PHP will not know how to access MySQL databases. If you need to obtain any of this software, see Appendix A, "Obtaining and Installing Software." Instructions for obtaining the example scripts developed in this chapter are also given in that appendix. You can download the scripts to avoid typing them in yourself.

Under UNIX, PHP may be used with Apache either as a built-in module that is linked into the Apache executable binary, or as a standalone interpreter used as a traditional CGI program. Under Windows, PHP can run only as a standalone program at the moment, though there is work underway to develop an Apache PHP 4 module that will run under Windows NT.

For the most part, this chapter describes PHP functions only as they are needed for the discussion here. For a more comprehensive listing of all MySQL-related functions, see Appendix H, "PHP API Reference." You'll likely also want to consult the PHP manual, which describes the full range of functions that PHP provides, including functions for using databases other than MySQL (PHP is not limited to working with MySQL any more than DBI is). The manual is available from the PHP Web site at http://www.php.net/. This Web site also has the notes for migrating from PHP 3 to PHP 4.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.246.193