phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


ADOdb: Introduction

Tag: adodb, database, database layer   Category: PHP Database
post: 29 Oct 2007 read: 1,944


You can amaze your client by saying "It's no problem you will use mysql, mssql, oracle, etc. Our web application support all major database without change codes". Wow, it's advantage for your promotion. The magic secret is php ADOdb. PHP's database access functions are not standardised. This creates a need for a database class library to hide the differences between the different database API's (encapsulate the differences) so we can easily switch databases. ADOdb currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access, ADO and ODBC. We have had successful reports of connecting to Progress and DB2 via ODBC. Unique Features of ADOdb (from manual):
  • Easy for Windows programmers to adapt to because many of the conventions are similar to Microsoft's ADO. Unlike other PHP database classes which focus only on select statements, we provide support code to handle inserts and updates which can be adapted to multiple databases quickly. Methods are provided for date handling, string concatenation and string quoting characters for differing databases.
  • A metatype system is built in so that we can figure out that types such as CHAR, TEXT and STRING are equivalent in different databases.
  • Easy to port because all the database dependant code are stored in stub functions. You do not need to port the core logic of the classes.
  • PHP4 session support. See adodb-session.php.
Now, we try test this library.
  1. Download from sourceforge.
  2. Extract zip file to a web directory.
  3. Open a database manager (ex, phpmyadmin).
  4. Create a simple database for test (ex, "inventory").
  5. Create a simple table (ex, "products").
  6. Now, Try simple test. Write code below. Put in the same directory with folder adodb. Give name "adodbtest.php":
    
    <?php     
        include('adodb/adodb.inc.php'); 
        
        $databasetype = 'mysql'; 
        $server = 'localhost';
        $user   = 'root';
        $password = 'r0ot';
        $database = 'inventory';
        
        $db = ADONewConnection($databasetype); 
        $db->debug = true; 
        $db->Connect($server, $user, $password, $database); 
        $rs = $db->Execute('select * from products'); 
        print "<pre>"; 
        print_r($rs->GetRows()); 
        print "</pre>"; 
    ?>
    
  7. Execute that file.
Now, it's time to tell our client... "Don't worry, My web application support your database".


Series this article:
ADOdb: Introduction
ADOdb: Connection Statement
ADOdb: Advance Select Statement
ADOdb: How to show tables
ADOdb: How to show fields
ADOdb: How to show databases
ADOdb: Caching of Recordset
ADOdb: Recordset to HTML
ADOdb: Multi Database Connection
ADOdb: Data Dictionary
ADOdb: Quick Export Data
ADOdb: Insert data style
ADOdb: Replace Data
ADOdb: Log Query
PHP ADOdb: Understanding Pivot Table For Reporting
PHP ADOdb: Creating Pivot Table
PHP ADOdb: Creating Query to Build Pivot Table

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting