PHP
  Home arrow PHP arrow Page 8 - Database Abstraction With PHP
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
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? 
PHP

Database Abstraction With PHP
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 49
    2002-02-13

    Table of Contents:
  • Database Abstraction With PHP
  • Alphabet Soup
  • Sultans Of Swing
  • Independence Day
  • Different Strokes
  • The Number Game
  • Preparing For The Long Haul
  • Commitment Issues
  • No News Is Good News
  • Catch Me If You Can
  • Once Again, The Headlines

  • 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
     
     
    IBM Developerworks
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Database Abstraction With PHP - Commitment Issues
    (Page 8 of 11 )

    If your database system supports transactions (MySQL doesn't, but quite a few others do), you'll be thrilled to hear that PHP's database abstraction layer comes with a bunch of methods that allow you to transparently use this feature in your scripts. What you may not be so thrilled about, though, is the fact that it also allows me the opportunity to make a few bad puns.

    The following example demonstrates:

    <?php // uncomment this to see plaintext output in your browser // header("Content-Type: text/plain"); // include the DB abstraction layer include("DB.php"); // connect to the database (Oracle) $dbh = DB::connect("oci8://john:doe@listener/db287"); // turn off autocommit $dbh->autoCommit(false); // execute one query $dbh->query("INSERT INTO cds (id,title, artist) VALUES(SEQ_CDS_ID.nextval, 'Weathered', 'Creed')"); // commit the data to database $dbh->commit(); // execute one more query $dbh->query("INSERT INTO cds (id,title, artist) VALUES(SEQ_CDS_ID.nextval, 'The Joshua Tree', 'U2')"); // now rollback to previous stage $dbh->rollback(); // now if you check the contents of the table // only one entry will be visible // as the second action has been rolled back // close database connection $dbh->disconnect(); ?>
    The first step here is to turn off auto-committal of data to the database, via the autoCommit() method. Once that's done, you can go ahead and execute as many queries as you like, secure in the knowledge that no changes have (yet) been made to the database.

    Once your fear of commitment passes (and I don't mean just here, oh no!), you can save your data to the database via a call to the commit() method. In the event that you realize you made a mistake, you can uncommit yourself gracefully (notice how this never happens in real life?) with the rollback() function. It's simple, it's healthy, and the guy who manages to apply it to human behaviour will make a gazillion.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway