Call a C# .net .dll script using PHP
I have a C# .net dll script that calls a SQL stored procedure that SELECT
s data in order to do run relevant methods.
I need to run the dll using PHP as my entire application is built in PHP.
What is the best way of doing this?
I'm not experienced at all with C#.
EDIT
I successfully registered the .net dll using:
RegAsm.exe DllName.dll /tlb:DllName.tlb
I should now be able to use PHP's COM()
method as described below to call the dll's functions/methods.
But will these functions still be accessible through the COM()
method as the .net dll was registered as an assembly? Does it make a difference?
EDIT
After registering the .net dll assembly I get an error message when I try to call the method using 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 internal server 500
error
Is this because PHP doesn't communicate with .net 4 assemblies?
c# php
|
show 3 more comments
I have a C# .net dll script that calls a SQL stored procedure that SELECT
s data in order to do run relevant methods.
I need to run the dll using PHP as my entire application is built in PHP.
What is the best way of doing this?
I'm not experienced at all with C#.
EDIT
I successfully registered the .net dll using:
RegAsm.exe DllName.dll /tlb:DllName.tlb
I should now be able to use PHP's COM()
method as described below to call the dll's functions/methods.
But will these functions still be accessible through the COM()
method as the .net dll was registered as an assembly? Does it make a difference?
EDIT
After registering the .net dll assembly I get an error message when I try to call the method using 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 internal server 500
error
Is this because PHP doesn't communicate with .net 4 assemblies?
c# php
2
best way is to convert the query to a PHP implementation. You could also use theexec()
php function, but I think use of this code when the frontend isn't the shell is considered bad practice..
– RichardBernards
Nov 19 '14 at 12:09
I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.
– proPhet
Nov 19 '14 at 12:11
What do you mean by a C# script? C# is compiled into an exe or dll.
– Ben Robinson
Nov 19 '14 at 12:13
Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...
– RichardBernards
Nov 19 '14 at 12:13
the script is a .dll file
– proPhet
Nov 19 '14 at 12:14
|
show 3 more comments
I have a C# .net dll script that calls a SQL stored procedure that SELECT
s data in order to do run relevant methods.
I need to run the dll using PHP as my entire application is built in PHP.
What is the best way of doing this?
I'm not experienced at all with C#.
EDIT
I successfully registered the .net dll using:
RegAsm.exe DllName.dll /tlb:DllName.tlb
I should now be able to use PHP's COM()
method as described below to call the dll's functions/methods.
But will these functions still be accessible through the COM()
method as the .net dll was registered as an assembly? Does it make a difference?
EDIT
After registering the .net dll assembly I get an error message when I try to call the method using 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 internal server 500
error
Is this because PHP doesn't communicate with .net 4 assemblies?
c# php
I have a C# .net dll script that calls a SQL stored procedure that SELECT
s data in order to do run relevant methods.
I need to run the dll using PHP as my entire application is built in PHP.
What is the best way of doing this?
I'm not experienced at all with C#.
EDIT
I successfully registered the .net dll using:
RegAsm.exe DllName.dll /tlb:DllName.tlb
I should now be able to use PHP's COM()
method as described below to call the dll's functions/methods.
But will these functions still be accessible through the COM()
method as the .net dll was registered as an assembly? Does it make a difference?
EDIT
After registering the .net dll assembly I get an error message when I try to call the method using 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 internal server 500
error
Is this because PHP doesn't communicate with .net 4 assemblies?
c# php
c# php
edited Nov 20 '14 at 12:13
proPhet
asked Nov 19 '14 at 12:08
proPhetproPhet
5232728
5232728
2
best way is to convert the query to a PHP implementation. You could also use theexec()
php function, but I think use of this code when the frontend isn't the shell is considered bad practice..
– RichardBernards
Nov 19 '14 at 12:09
I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.
– proPhet
Nov 19 '14 at 12:11
What do you mean by a C# script? C# is compiled into an exe or dll.
– Ben Robinson
Nov 19 '14 at 12:13
Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...
– RichardBernards
Nov 19 '14 at 12:13
the script is a .dll file
– proPhet
Nov 19 '14 at 12:14
|
show 3 more comments
2
best way is to convert the query to a PHP implementation. You could also use theexec()
php function, but I think use of this code when the frontend isn't the shell is considered bad practice..
– RichardBernards
Nov 19 '14 at 12:09
I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.
– proPhet
Nov 19 '14 at 12:11
What do you mean by a C# script? C# is compiled into an exe or dll.
– Ben Robinson
Nov 19 '14 at 12:13
Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...
– RichardBernards
Nov 19 '14 at 12:13
the script is a .dll file
– proPhet
Nov 19 '14 at 12:14
2
2
best way is to convert the query to a PHP implementation. You could also use the
exec()
php function, but I think use of this code when the frontend isn't the shell is considered bad practice..– RichardBernards
Nov 19 '14 at 12:09
best way is to convert the query to a PHP implementation. You could also use the
exec()
php function, but I think use of this code when the frontend isn't the shell is considered bad practice..– RichardBernards
Nov 19 '14 at 12:09
I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.
– proPhet
Nov 19 '14 at 12:11
I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.
– proPhet
Nov 19 '14 at 12:11
What do you mean by a C# script? C# is compiled into an exe or dll.
– Ben Robinson
Nov 19 '14 at 12:13
What do you mean by a C# script? C# is compiled into an exe or dll.
– Ben Robinson
Nov 19 '14 at 12:13
Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...
– RichardBernards
Nov 19 '14 at 12:13
Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...
– RichardBernards
Nov 19 '14 at 12:13
the script is a .dll file
– proPhet
Nov 19 '14 at 12:14
the script is a .dll file
– proPhet
Nov 19 '14 at 12:14
|
show 3 more comments
2 Answers
2
active
oldest
votes
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:
- 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.NETAppropriateVersion. - Create a COM object in PHP that references the class name of the DLL.
- 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.
4
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
I'm confused, where does themyMethod()
come from? is it instantiated there? how then do I call it?
– proPhet
Nov 19 '14 at 13:27
You'd replacemyMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.
– Eric Eskildsen
Nov 19 '14 at 13:31
I tried registering the dll but I got an error saying that..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
1
Try usingregasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead ofregsvr32
. The syntax is the same:regasm yourdllname.dll
.
– Eric Eskildsen
Nov 19 '14 at 14:28
|
show 1 more comment
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
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27016470%2fcall-a-c-sharp-net-dll-script-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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:
- 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.NETAppropriateVersion. - Create a COM object in PHP that references the class name of the DLL.
- 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.
4
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
I'm confused, where does themyMethod()
come from? is it instantiated there? how then do I call it?
– proPhet
Nov 19 '14 at 13:27
You'd replacemyMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.
– Eric Eskildsen
Nov 19 '14 at 13:31
I tried registering the dll but I got an error saying that..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
1
Try usingregasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead ofregsvr32
. The syntax is the same:regasm yourdllname.dll
.
– Eric Eskildsen
Nov 19 '14 at 14:28
|
show 1 more comment
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:
- 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.NETAppropriateVersion. - Create a COM object in PHP that references the class name of the DLL.
- 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.
4
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
I'm confused, where does themyMethod()
come from? is it instantiated there? how then do I call it?
– proPhet
Nov 19 '14 at 13:27
You'd replacemyMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.
– Eric Eskildsen
Nov 19 '14 at 13:31
I tried registering the dll but I got an error saying that..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
1
Try usingregasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead ofregsvr32
. The syntax is the same:regasm yourdllname.dll
.
– Eric Eskildsen
Nov 19 '14 at 14:28
|
show 1 more comment
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:
- 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.NETAppropriateVersion. - Create a COM object in PHP that references the class name of the DLL.
- 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.
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:
- 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.NETAppropriateVersion. - Create a COM object in PHP that references the class name of the DLL.
- 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.
edited Oct 17 '18 at 19:33
answered Nov 19 '14 at 12:42
Eric EskildsenEric Eskildsen
1,08811327
1,08811327
4
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
I'm confused, where does themyMethod()
come from? is it instantiated there? how then do I call it?
– proPhet
Nov 19 '14 at 13:27
You'd replacemyMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.
– Eric Eskildsen
Nov 19 '14 at 13:31
I tried registering the dll but I got an error saying that..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
1
Try usingregasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead ofregsvr32
. The syntax is the same:regasm yourdllname.dll
.
– Eric Eskildsen
Nov 19 '14 at 14:28
|
show 1 more comment
4
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
I'm confused, where does themyMethod()
come from? is it instantiated there? how then do I call it?
– proPhet
Nov 19 '14 at 13:27
You'd replacemyMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.
– Eric Eskildsen
Nov 19 '14 at 13:31
I tried registering the dll but I got an error saying that..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
1
Try usingregasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead ofregsvr32
. The syntax is the same:regasm yourdllname.dll
.
– Eric Eskildsen
Nov 19 '14 at 14:28
4
4
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
Option 3 Access the DLL through a webservice
– DarkBee
Nov 19 '14 at 12:45
I'm confused, where does the
myMethod()
come from? is it instantiated there? how then do I call it?– proPhet
Nov 19 '14 at 13:27
I'm confused, where does the
myMethod()
come from? is it instantiated there? how then do I call it?– proPhet
Nov 19 '14 at 13:27
You'd replace
myMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.– Eric Eskildsen
Nov 19 '14 at 13:31
You'd replace
myMethod
with the name of the method (function) that calls the SQL stored procedure in your DLL.– Eric Eskildsen
Nov 19 '14 at 13:31
I tried registering the dll but I got an error saying that
..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
I tried registering the dll but I got an error saying that
..the-entry point DllRegisterServer was not found
– proPhet
Nov 19 '14 at 14:13
1
1
Try using
regasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32
. The syntax is the same: regasm yourdllname.dll
.– Eric Eskildsen
Nov 19 '14 at 14:28
Try using
regasm
(C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32
. The syntax is the same: regasm yourdllname.dll
.– Eric Eskildsen
Nov 19 '14 at 14:28
|
show 1 more comment
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
add a comment |
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
add a comment |
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
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
answered Mar 5 '17 at 19:40
daviddavid
111
111
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27016470%2fcall-a-c-sharp-net-dll-script-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
best way is to convert the query to a PHP implementation. You could also use the
exec()
php function, but I think use of this code when the frontend isn't the shell is considered bad practice..– RichardBernards
Nov 19 '14 at 12:09
I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.
– proPhet
Nov 19 '14 at 12:11
What do you mean by a C# script? C# is compiled into an exe or dll.
– Ben Robinson
Nov 19 '14 at 12:13
Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...
– RichardBernards
Nov 19 '14 at 12:13
the script is a .dll file
– proPhet
Nov 19 '14 at 12:14