PHP
  Home arrow PHP arrow Page 3 - Using the .NET Assembly in PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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

Using the .NET Assembly in PHP
By: Jayesh Jain
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2002-10-15

    Table of Contents:
  • Using the .NET Assembly in PHP
  • Creating an Assembly
  • Creating the PHP File
  • Conclusion

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


    Using the .NET Assembly in PHP - Creating the PHP File


    (Page 3 of 4 )

    Create a text file with the following content and save the file as phpnet.php in c:\inetpub\wwwroot folder (or your webserver http root folder):

    <?
    $MyObj = new COM ("phpclass.HealthRecord.patient");
    $MyObj->lmp = "05/08/2002";

    echo "LMP : $MyObj->lmp";
    echo "<BR>EDD : $MyObj->edd";
    ?>


    Examining the Code
    Firstly, we create a COM object for the object that we just installed and registered. COM interop makes the .NET assembly look like COM objects, and we can use the same syntax as we use to create typical COM objects in PHP:

    $MyObj = new COM ("phpclass.HealthRecord.patient");

    Next, we set the lmp property to a valid date, which will then be used to calculate the edd:

    $MyObj->lmp = "05/08/2002";

    Now we output the LMP property in a human-readable date format. We also output the calculated EDD property to the browser:

    echo "LMP : $MyObj->lmp";
    echo "<BR>EDD : $MyObj->edd";


    Running the Code
    Open your favorite browser and surf to http://localhost/phpnet.php to see the PHP file in action:

    Our PHP script in action

    Using COM Interop in VB6
    You could use the same steps as shown above to create a COM wrapper around the .NET assembly and use it in VB6. Here's the VB6 code for your reference:

    Set MyObj = CreateObject("phpclass.HealthRecord.patient")
    MyObj.lmp = "05/08/2002"
    MsgBox "LMP : " & MyObj.lmp
    MsgBox "EDD : " & MyObj.edd


    Unregistering the Type Library
    To unregister the type library, run regasm with the /unregister switch and specify the assembly path:

    regasm /unregister c:/tgol/phpclass/bin/phpclass.dll

    Unregistering the type library

    Removing the Assembly from Global Assembly Cache
    To remove the assembly from the GAC, run gacutil with the /u switch and specify the assembly name, like this:

    gacutil /u phpclass

    Don't specify the path to the assembly and also don't add the .dll extension to the assembly name.

    Removing the assembly from the GAC

    More PHP Articles
    More By Jayesh Jain


       · Really usefull .Net assembly use in PHP overall.Helped me start my own...
     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT