PHP
  Home arrow PHP arrow Page 8 - PHP and COM
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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

PHP and COM
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 13
    2002-04-23


    Table of Contents:
  • PHP and COM
  • Striving To Excel
  • The Number Game
  • Export Potential
  • Keeping It Simple
  • Access-ing The Web
  • All For One, And One For All
  • New Coins For Old
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    PHP and COM - New Coins For Old
    ( Page 8 of 9 )

    If the user chooses to add a new record, the value of $nextopid is set to "add_process". And when the PHP script is called to process the form data, this is the code block that gets executed.

    <?php if($nextopid == "add_process") { // open connection $DB_Conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $DB_Conn->Open("phpcom"); // run query $Query = "INSERT INTO coins(name, country, weight, year, remarks) VALUES('".trim($name)."','".trim($country)."',".trim($weight).",".trim($ year ).",'".trim($remarks)."')"; $RS_Record = $DB_Conn->Execute($Query); // redirect browser to list header("Location:".$PHP_SELF."?nextopid=list&previousopid=".$nextopid); // end of "add" processor } ?>
    Similarly, when the script is called to edit a record, this code block will get executed.

    <?php if($nextopid == "edit_process") { // open connection $DB_Conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $DB_Conn->Open("phpcom"); // execute query $Query = "UPDATE coins SET name = '".trim($name)."',country = '".trim($country)."',weight = ".trim($weight).",year = ".trim($year).",remarks = '".trim($remarks)."' WHERE id = $id"; $RS_Record = $DB_Conn->Execute($Query); // redirect browser back to list header("Location:".$PHP_SELF."?nextopid=list&previousopid=".$nextopid); // end of "edit" processor } ?>
    Fairly simple and self-explanatory, this - depending on the type of operation, an appropriate SQL query is generated and executed.

    Finally, record deletion. This is activated by calling the script with the value of $nextopid set to "delete", and an additional record ID to identify which record is to be deleted. Take a look:

    <?php if($nextopid == "delete") { // delete selected records $DB_Conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $DB_Conn->Open("phpcom"); $Query = "DELETE FROM coins WHERE id = $id"; $RS_Record = $DB_Conn->Execute($Query); header("Location:".$PHP_SELF."?nextopid=list&previousopid=".$nextopid); // end of "delete" condition } ?>
    Short and sweet. And when you try the entire thing out, you'll see that you can add, edit and delete records to the Access database, via the COM object. Ain't it cool?

     
     
    >>> More PHP Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT