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.
How about one more, this time using the third member of the Microsoft Office family - Microsoft Access?
What do I have in mind for this example? Well, I plan to manipulate (add/edit/delete) records in a Microsoft Access database using a Web browser and a bunch of PHP scripts.
At first glance, this might not seem like a big deal. You're probably already familiar with manipulating a MySQL database with PHP - PHP comes with built-in functions to do this, and the MySQL connectivity in PHP is easily one of the more important reasons for the language's popularity. And you might also be familiar with manipulating Microsoft Access tables via ODBC. But what I have in mind is a little different.
Since this is an article about COM, I don't intend to use either ODBC or PHP's MySQL functions to modify the Microsoft Access database. Instead, I'll be using the methods and properties of the ADODB COM object, in order to demonstrate an alternative technique.
First, here's the Microsoft Access database, holding information on my coin collection in a single table. You may assume that the database is named "phpcom" and the table containing the records is called "coins".
Now, I need to create a Web based interface to modify this database with PHP.
The first step is to create a Data Source Name (DSN) in order to access the database through ODBC. Pop open your Control Panel and use the ODBC module to create this DSN. Tab to the "System DSN" section, and add a new DSN.
Select "Microsoft Access Driver" from the list of available drivers. Set a data source name ("phpcom"), a description ("DSN for PHP/Access connection") and the name of the database to be accessed ("phpcom").
Save your changes, and go back to your PHP editor. It's time to start writing some code.