Database Articles
  Home arrow Database Articles arrow Page 3 - 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::connect


    (Page 3 of 7 )

    mixed connect (string $dsn [, array $options])

    That is our connect function. It is what we will use to connect to the database. Its actual use will look something like:

    $db = DB::connect("mysql://user:pass@host/db_name", FALSE);

    It will return a connection object or an error object which will be stored in $db. You may be wondering what that wierd :: is. Well, DB is the class for data abstraction and connect is the function. Normally you would see it look like DB->connect(). The reason for the :: is so that we can use the connect function without creating an instance of the class DB. Maybe a little bit different than you are used to, but it has its uses. The :: can also be used to access a function of a base class when you are dealing with inherited classes.

    You can see that we passed the connect function what sort of looks like a URL. This is a dsn, or data source name. Here you pass it the database type and other connection information such as username and password. Here is a list of supported database types:mysql -> MySQLpgsql -> PostgreSQLibase -> InterBasemsql -> Mini SQLmssql -> Microsoft SQL Serveroci8 -> Oracle 7/8/8iodbc -> ODBC (Open Database Connectivity)sybase -> SyBaseifx -> Informixfbsql -> FrontBase

    The second, optional parameter is whether to use persistent connections or not. Not all databases support persistent connections and the default for this parameter is false.

    Here is how it is commonly used:

    <?php
    require_once 'DB.php';

    $user 'foo';
    $pass 'bar';
    $host 'localhost';
    $db_name 'clients_db';

    $dsn "mysql://$user:$pass@$host/$db_name";

    $db DB::connect($dsnfalse);
    ?>

    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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek