Solution to the php com component error: 1. Modify the configuration "com.allow_dcom" and "php_com_dotnet.dll" in php.ini; 2. Use vs2013 to write the COM component.
The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
Reasons why php fails to load COM components and their solutions
Personally, the most convenient way to call interfaces of other programming languages in php is Use COM components. Recently, I just started to come into contact with PHP. When I was studying calling COM components written in C, I encountered the error "'Failed to create COM object". It took a lot of effort to finally solve it.
Higher versions of php need to manually enable COM support. Basically, modify the configuration in php.ini to com.allow_dcom = true and extension=php_com_dotnet.dll. If this is the error, it can be easily solved. In fact, I think this kind of configuration error is rarely made by people. Many people say that they can test whether the COM component support is normal by loading and testing wps or word components. However, due to permission issues, this testing method is not very practical. Easy to use. Later, I found $db = new COM("ADODB.Connection",NULL, 65001); in the http://php.net/manual/zh/class.com.php document description; after testing, it loaded normally, indicating that There must be something wrong with the COM component I wrote, and it turned out to be the case.
There were many examples of PHP loading COM components written in C on the Internet before. It may be because the PHP version is too low, and that way of creating components is no longer suitable. If you are using a version before php5.2, it may be correct. I'm using php5.5 and was misled.
My PHP version is 5.5.12, and I use vs2013 to write COM components. The following is the process:
1. Find vs2013 in the launch bar, right-click to open it with administrator rights, so use the administrator identity It is turned on because it will be convenient when registering the COM component later. Create a new ATL project in c,
2, click Finish, right-click on the project to add a class, and select ATL COM 10.
#3. Right-click on the project to add a class. The following is the most critical point. The ProgID in the lower right corner must be added manually. The format is "Project name. Abbreviation". The project name is the name of the generated dll. It will also be written like this when loading it in PHP later. The second item is The abbreviation, not the class name. If this place is written incorrectly, although the component can be registered successfully, it will not be recognized in PHP.
#4. Add a method on Itest. I will not write this in detail. I added an add as follows [Recommended learning: "PHP Video tutorial》】
STDMETHODIMP Ctest::add(LONG a, LONG b, LONG* c) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: 在此添加实现代码 *c = a + b; return S_OK; }
5, then compile and automatically register as a component, and restart the apache service. The following call is made in the php script:
<?php $conn = new COM("ATLProject3.test") or die("Cannot start ADO"); $com = 2; $conn->add(10, 2, $com); echo $com; ?>
Note that the format of "component name.abbreviation" is correct. In the online example, it is "component name.class name". It may be a version problem. Anyway, my call failed.
6. Enter your PHP project directory into the browser, and it will show that the COM component is loaded normally. The COM component is successfully used to make the output of 10 plus 2 as 12.
The above is the detailed content of How to solve the error problem of php com component. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function