Database Articles
  Home arrow Database Articles arrow Page 6 - Database Abstraction with PEAR
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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


     

    DATABASE ARTICLES ARTICLES

    - More on Query Optimization for Oracle Databa...
    - Query Optimization in Oracle
    - Clusters and Other Data Structures for Oracle
    - Using Indexes with an Oracle Database
    - The Basics of Data Structures in Oracle
    - Oracle Data Structures
    - Best Practices for PL/SQL Variables
    - What`s Code Without Variables?
    - Clauses, Sorting, and SQL Queries
    - The From Clause and SQL Queries
    - Query Primer
    - Full Text Searches and Strings
    - Searching with Strings
    - Pattern Matching with Strings
    - Working with Cases of Strings





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek