Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have learnt that we can create some (I think only some) .net objects in PHP using DOTNET constructor like this:
PHP
$dotNETobj = new DOTNET("assembly full name", "classname");

I have played with it creating some .NET object like Hashtable, Stack... and I tried with SqlConnection but it failed, maybe I made something wrong. Could you please tell me if it is possible to create that object in PHP? If possible, could you post some code here for that?
Here is my try:
PHP
$sqlcon = new DOTNET("System.Data", "SqlConnection");

The error message is too long, I'll post only some of it that I think it is important here:
"...'Failed to instantiate .Net object... The system cannot find the specified.  ' in myurl Stack trace:..."
All are in a line without any break. I can't understand why PHP can give us such an illegible error message? It is too complicate to any newbie and maybe many intermediate programmers, I'm sure to say that. Fortunately, dot net is not the same!
Your help would be appreciated!
Thank you!
Posted
Updated 29-Mar-12 4:57am
v2
Comments
Peter_in_2780 29-Mar-12 19:31pm    
There is a very good reason the error message does not contain any line breaks (although it DOES contain "\n" sequences for later processing). The message is logged to a server error log file, and there are many programs that process those log files. Multiline log messages would break the formatting expected by those programs.
Meanswhile, it seems the .NET assembly can't be found. I'd start looking for it. Do you have the .NET runtine installed, like the PHP manual says?
btw, the error message is not too big to post, and contains useful information you haven't shown us.
supernorb 29-Mar-12 20:58pm    
No, I don't think so. I have experienced programming with .NET for months and I have already installed Framework 3.5 on my computer going with VS 2008. The error message is long but it contains my url and that's why it is long, I think the what I posted is the most important. You can reproduce my error message simply by typing only one line of code that I posted (creating a .net object using DOTNET constructor). There was no other code involving here, I'm sure because I tested with only that line in a php file.
Thank you for your help!

1 solution

I don't use PHP, but here's a shot in the dark that might just be your issue...

The SqlConnection class resides in the namespace System.Data.SqlClient. Perhaps you need to specify that when you call DOTNET. For example, you might try some of these:
PHP
$sqlcon = new DOTNET("System.Data", "System.Data.SqlClient.SqlConnection");
$sqlcon = new DOTNET("System.Data", "SqlClient.SqlConnection");
$sqlcon = new DOTNET("System.Data.SqlConnection", "SqlConnection");


Seems to me it would have no other way of knowing where SqlConnection is. There could, in fact, be two SqlConnection classes in different namespaces and it wouldn't know which to pick.

Alternatively, create a wrapper class for SqlConnection and build your own DLL that you can import. That might get complicated though... for example, you may have to put the DLL into the GAC.
 
Share this answer
 
Comments
supernorb 10-Apr-12 14:33pm    
Thank you, I'm sorry to say that all your suggestions didn't make any change, the error was still thrown.
I think SqlConnection can't be created in PHP, any way thank you so much, it seems that you are a pro of asp.net, and I'm going to learn asp.net soon or later, then I will need your help much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900