Call C # .net.dll script using PHP

I have a C # .net dll script that calls a SQL stored procedure for the SELECT

data to execute the appropriate methods.

I need to run a dll using PHP as my whole application is built in PHP.

What's the best way to do this?

I have no problem with C # at all.

EDIT

I have successfully registered dll.net using:

RegAsm.exe DllName.dll /tlb:DllName.tlb

      

Now I have to use PHP method COM()

as described below to call dll functions / methods.

But will these functions still be available through the method COM()

, since DLL.net was registered as an assembly? Does it matter?

EDIT

After registering a .net dll assembly, an error message appears when trying to call a method with COM()

:

"PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed
 to create COM object `DllName.ClassName': Invalid syntax"

      

EDIT

Tried using:

new DOTNET('DllName, Version=4.0.30319.33440, Culture=neutral,
PublicTokenKey=14843e0419858c21', 'ClassName');

      

got an error internal server 500

Is it because PHP is not linking to .net 4 assemblies?

+3


source to share


2 answers


Option 1: use a DLL

You can call the function using the PHP COM class.

You will need to run PHP on Windows, which I assume you are using if you are using a C # DLL.

Steps:

  • Register the DLL using a command regasm yourdllname.dll

    on the command line or in the Run dialog box. You have one RegAsm.exe file for each .NET version installed on your machine, so be sure to run it for the .NET version the DLL runs by running it from% windir% \ Microsoft.NET \ AppropriateVersion.
  • Create a COM object in PHP that references the DLL class name.
  • Call a function that will be available as a method of the generated COM object.


Example:

$object = new COM('MyDllProjectName.MyDllClassName');
$object->myMethod();

      

Option 2: rewrite in PHP

As mentioned, a cleaner, cross-platform option is to re-inject the SQL query into PHP directly, especially if the only reason to use the DLL is to execute the query.

+2


source


Using COM directly has many caveats and problems.

There is a library called NetPhp that abstracts on top of COM using reflection so that you can call ANY .dll from PHP without issue:



http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php

0


source







All Articles