Home arrow PHP arrow Page 8 - PHP and COM

New Coins For Old - PHP

You've already seen how PHP can be used to interface with Java components and JavaBeans. But here's something you didn't know - PHP can (shock shock! horror horror!) even be used to interface with Microsoft COM objects on the Windows platform. Will this be a happy marriage? Read on to find out.

TABLE OF CONTENTS:
  1. PHP and COM
  2. Striving To Excel
  3. The Number Game
  4. Export Potential
  5. Keeping It Simple
  6. Access-ing The Web
  7. All For One, And One For All
  8. New Coins For Old
  9. Link Zone
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 15
April 23, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: