Mysql entry-level series: PHP script features PHP is a scripting language that allows you to write Web pages containing embedded code and execute the code as long as you access the page, the code can also generate dynamic content as part of the output and send it to the client's Web browser. This chapter describes how to use PHP to compile a MySQL-based We B application. For comparison between C and PHP and Perl DBI APIs, see chapter 5th "MySQL programming introduction ".
The examples in this chapter use the sample database samp_db, which uses the tables created for the credit retention scheme and the tables created for the historical consortium in chapter 1st "MySQL and SQL introduction. While PHP 4 was still in? In the test phase, it may have been released when you read this book, but it still involves PHP 3 content. Compatibility with PHP 3 is a clear design goal of PHP 4, so all aspects of PHP 3 mentioned here can be applied to PHP 4. There are a set of precautions for porting changes from PHP 3 to PHP 4. If PHP 4 is used, you should read the comments.
This chapter assumes that PHP and Apache Server are used in combination. You must install the MySQLC client library and header files because these files are required when you create PHP. otherwise, PHP does not know how to access the MySQL database. To obtain such software, see Appendix A "obtain and install software ". The appendix also describes the instance scripts developed in this Chapter. you can download these scripts directly.
In a UNIX environment, PHP can be used as a built-in module for Apache. this module is connected to an executable binary program of Apache, or as an independent interpreter for a traditional CGI program. In Windows, although the development of Apache PHP 4 module running in Windows NT is in progress, PHP can only be run as an independent program at the moment.
Most of the sections in this chapter illustrate the required PHP functions. For more information about MySQL functions, see Appendix H "php api Reference" or the PHP Manual, which describes all functions provided by PHP, including the use of database functions other than MySQL (when using MySQL, the unrestricted part of PHP is only DBI ). This manual can be downloaded from the PHP Web site: http://www.php.net /. This Web site also has precautions for porting from PHP 3 to PHP 4.
The file name of a PHP script has an extension that allows the Web server to identify the file name and execute the PHP interpreter to process it. If an unrecognized extension is used, the PHP script is treated as plain text. The extension used in this chapter is. p h p, and other common extensions are. php3 and. p h t m l. For instructions on configuring Apache to identify extensions, see Appendix. If you are not familiar with Apache installation on the machine, check with the system administrator to find out the appropriate extension that can be used.