Database Articles

  Home arrow Database Articles arrow Page 6 - Database Abstraction with PEAR
DATABASE ARTICLES

Database Abstraction with PEAR
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-07-28

    Table of Contents:
  • Database Abstraction with PEAR
  • What is PEAR?
  • DB::connect
  • DB::disconnect
  • DB::isError
  • DB::getOne and DB::query()
  • DB_Result::fetchRow

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Database Abstraction with PEAR - DB::getOne and DB::query()


    (Page 6 of 7 )

    mixed &getOne (string $query [, array $params])

    Now, this is a useful little function. This allows you to grab the first column in the first row of data that a query returns. It is very useful for doing count functions or sum functions. It returns the value of the first column in the first row or an error object.

    A typical use would be:

    <?php
    $numrows 
    $db->getOne('SELECT count(*) FROM mystuff');
    ?>

    One nice thing about DB::getone is that it does the query, gets the results, and frees the results. No need to worry about cleanup with this function.

    mixed &amp;query (string $query [, array $params])

    This is the general purpose query function. On failure it will return an error object. On success it will return either a DB_OK or a result set object. A DB_OK is a PEAR constant that just tells you the query executed successfully. You will receive a DB_OK for any query that executes properly that doesn't return a result set, i.e. an INSERT or UPDATE.

    Usage for this function:

    <?php
    $sql 
    "SELECT * FROM mystuff ORDER BY stuff";
    $result $db->query($sql);
    ?>

    More Database Articles Articles
    More By Matt Wade

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


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