Call a C# .net .dll script using PHP

后端 未结 2 1794
不知归路
不知归路 2020-12-19 11:43

I have a C# .net dll script that calls a SQL stored procedure that SELECTs data in order to do run relevant methods.

I need to run the dll using PHP as

相关标签:
2条回答
  • 2020-12-19 12:44

    Option 1: Use the DLL

    You can call the function using PHP's COM class.

    You'll need to be running PHP on Windows, which I assume you are if you're using a C# DLL.

    Steps:

    1. Register the DLL using the command regasm yourdllname.dll in Command Prompt or the Run dialog. You have one RegAsm.exe for each version of .NET installed on your computer, so make sure to execute the one for the version of .NET that the DLL targets by running it from %windir%\Microsoft.NET\AppropriateVersion.
    2. Create a COM object in PHP that references the class name of the DLL.
    3. Call the function, which will be available as a method of the COM object you've created.

    Example:

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

    Option 2: Rewrite in PHP

    As has been mentioned, the cleaner, cross-platform option is to re-implement the SQL query in PHP directly, especially if your only reason for using the DLL is to run a query.

    0 讨论(0)
  • 2020-12-19 12:45

    Using COM directly has many caveats and issues.

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

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

    0 讨论(0)
提交回复
热议问题