Example 8-1 is a program to build an HTML table of information about science fiction books. It demonstrates how to use the PEAR DB library (which comes with PHP) to connect to a database, issue queries, check for errors, and transform the results of queries into HTML. Be sure to verify how to turn on PEAR with your setup of PHP, as the Unix/Linux flavor is slightly different to that of Windows. Go to http:// www.pear.php.net/manual/en/installation.getting.php for a starting point on installation. The library is object-oriented, with a mixture of class methods (DB::connect(), DB::iserror()) and object methods ($db->query(),$q->fetchInto()). Example 8-1. Display book information <html><head><title>Library Books</title></head> <table border=1> // issue the query // generate the table The output of Example 8-1 is shown in Figure 8-1.
blog comments powered by Disqus |