Home arrow MySQL arrow Page 4 - PHP, MySQL and the PEAR Database

PEAR error reporting - MySQL

In this conclusion to a three-part series, you will add PEAR into the mix of what you have already learned. This article is excerpted from chapter 9 of Learning PHP and MySQL, written by Michele Davis and Jon Phillips (O'Reilly, 2006; ISBN: 0596101104). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

TABLE OF CONTENTS:
  1. PHP, MySQL and the PEAR Database
  2. Rewriting the Books Example with PEAR
  3. Creating a connect instance
  4. PEAR error reporting
By: O'Reilly Media
Rating: starstarstarstarstar / 8
May 31, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The function DB::isError will check to see whether the result that's been returned to you is an error or not. If it is an error, you can use DB::errorMessage to return a text description of the error that was generated. You need to pass DB::errorMessage the return value from your function as an argument.

Here you rewrite the PEAR code to use error checking:

  <?php
  if ( DB::isError( $demoResult = $db->query( $sql)))
  {
    
echo DB::errorMessage($demoResult);
  } else {
     while ($demoRow = $demoResult->fetchRow()) {
            echo $demoRow[2] . '<br />';
     }
  }
  ?>

Now that you have a good handle on connecting to the database and the various functions of PEAR, we're going to talk about forms. Forms provide a way to send substantial data from the user to the server where it can be processed.

Chapter 9 Questions

Question 9-1.  Create a PEAR-style connect string to connect to this database:

hostname: oreilly.com

database name: survey

username: joe

password: my$ql

Question 9-2.  Using the parameters in Question 9-1, write the non-PEAR PHP code to connect to a database and select the instance.

Question 9-3.  Using the connection from Question 9-2, write the non-PEAR PHP code to fetch and display the results of the query select * from authors;.

Question 9-4.  What are the advantages of using PEAR?

See the Appendix for the answers to these questions.



 
 
>>> More MySQL Articles          >>> More By O'Reilly Media
 

blog comments powered by Disqus
   

MYSQL ARTICLES

- Xeround Releases Free Version of MySQL Cloud...
- Oracle Announces New MySQL Specialization
- Constant Contact Chooses SkySQL for MySQL Su...
- Revoke Statement in MySQL
- The Grant Statement in MySQL
- SuccessBricks Announces ClearDB Availability...
- Building a PHP ORM: Deploying a Blog
- TROSYS Launches Free MySQL Manager and Admin...
- Building an ORM in PHP: Domain Modeling
- Building an ORM in PHP
- MySQL Leads Open Source Market, Gets Cluster...
- Oracle Announces Milestone Release for MySQL
- How to Stop SQL Injection Attacks
- New Defragmentation Solution for SQL Server
- Comparison of MyISAM and InnoDB MySQL Databa...


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: