When using a C program to access a MySQL database the exe produces no output but does provide an error code. Modifying the code to do a simple "Hello World" is successful. Running either of these exe programs on the Windows command line does work - ie the program to access the database returns rows of data. There are no error messages in Events (application or other).
Development environment
- Windows 11, Apache 2.4, MySQL 8.0.33, MSYS2 (I used:
pacman -S mingw-w64-ucrt-x86_64-gcc to get gcc
) - Using MSYS2 UCRT64 application to compile the c code
- Compiled using:
gcc firstc.c -o atest.exe -I'c:\Program Files\MySQL\MySQl Server 8.0\include' -L'c:\Program Files\MySQL\MySQl Server 8.0\lib' -llibmysql
C code -> compiles to atest.exe with no errors
#include <mysql.h>
#include <stdio.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "local";
char *database = "care";
conn = mysql_init(NULL);
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
printf("%s\n", mysql_error(conn));
return(5);
}
if (mysql_query(conn, "SELECT * FROM departments")) {
printf("%s\n", mysql_error(conn));
return(6);
}
res = mysql_use_result(conn);
while ( (row = mysql_fetch_row(res)) != NULL ) {
printf("%s %s %s\n", row[1], row[2], row[0]);
}
mysql_free_result(res);
mysql_close(conn);
}
Dumpbin gives with /dependents option for atest.exe:
File Type: EXECUTABLE IMAGE
Image has the following dependencies:
KERNEL32.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-private-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
libmysql.dll
The libmysql.dll has been copied from the MySQL folder to c:\windows\System32 and the c:\apache24\htdocs folder where the PHP code an exe resides. In addition it was copied to the folder where the source C code is compiled. Reason: just in case the PHP program/exe can not find/access it in the database folders.
PHP code to run the exe:
<?php
$command = "c:\apache24\htdocs\atest.exe 2>&1"; // should access MySQL and return rows
$response = system($command, $retval);
echo '<hr>Response: ' . $response . '<hr>Return value: ' . $retval;
?>
Browser window shows on running PHP code (exe which accesses MySQL):
Response:
Return value: -1073741515
i.e. there is no output but the error code 1073741515 is displayed
Expecting to get back rows of data from MySQL database.
UPDATE: 10/3/25
I checked again the error code and it should be -1073741515 (minus 1073741515). This converts to C0000135 Hex 2s complement.
Feedback responses:
-1073741515 as a file system error not MySQL error? If this is the case how do I identify which file is missing? Does it suggest that the issue is a file permissions error?
Apache runs as user: SYSTEM - The PC runs as a web server with Apache (not IIS) as the front end.
MySQL runs as a Network Service but can also run as a local user. The application runs with MySQL "root" access.
The PHP script runs as user SYSTEM
I am unable to get the c++ GetUserName function working - due to a lack of c++ programming experience and missing c++ dll's on my PC. ie my environment is set up for c programming not c++.
Response to possible duplicates: What does Error-code 0xc0000135 (or -1073741515 Exit-code) mean when starting a Windows
.NET Framework 3.5 is installed. Activating it starts IIS and locks out Apache. Currently it is switched off. If the issue is .NET -- I can still run a "Hello World" c program from PHP but cannot run a database query written in c as an exe and both programs work when run from the command line. i.e. .NET does not seem to be the issue. My anti-virus does not block the "Hello World" problem so I have discounted this as the problem. There are no .NET errors displayed when running the app.
I also turned on/off my anti-virus. This made no difference.
I have checked the Event logs and can find nothing related to this issue.
When running the app there is no message: "The application failed to initialize properly (0xc0000135)".
When using a C program to access a MySQL database the exe produces no output but does provide an error code. Modifying the code to do a simple "Hello World" is successful. Running either of these exe programs on the Windows command line does work - ie the program to access the database returns rows of data. There are no error messages in Events (application or other).
Development environment
- Windows 11, Apache 2.4, MySQL 8.0.33, MSYS2 (I used:
pacman -S mingw-w64-ucrt-x86_64-gcc to get gcc
) - Using MSYS2 UCRT64 application to compile the c code
- Compiled using:
gcc firstc.c -o atest.exe -I'c:\Program Files\MySQL\MySQl Server 8.0\include' -L'c:\Program Files\MySQL\MySQl Server 8.0\lib' -llibmysql
C code -> compiles to atest.exe with no errors
#include <mysql.h>
#include <stdio.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "local";
char *database = "care";
conn = mysql_init(NULL);
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
printf("%s\n", mysql_error(conn));
return(5);
}
if (mysql_query(conn, "SELECT * FROM departments")) {
printf("%s\n", mysql_error(conn));
return(6);
}
res = mysql_use_result(conn);
while ( (row = mysql_fetch_row(res)) != NULL ) {
printf("%s %s %s\n", row[1], row[2], row[0]);
}
mysql_free_result(res);
mysql_close(conn);
}
Dumpbin gives with /dependents option for atest.exe:
File Type: EXECUTABLE IMAGE
Image has the following dependencies:
KERNEL32.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-private-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
libmysql.dll
The libmysql.dll has been copied from the MySQL folder to c:\windows\System32 and the c:\apache24\htdocs folder where the PHP code an exe resides. In addition it was copied to the folder where the source C code is compiled. Reason: just in case the PHP program/exe can not find/access it in the database folders.
PHP code to run the exe:
<?php
$command = "c:\apache24\htdocs\atest.exe 2>&1"; // should access MySQL and return rows
$response = system($command, $retval);
echo '<hr>Response: ' . $response . '<hr>Return value: ' . $retval;
?>
Browser window shows on running PHP code (exe which accesses MySQL):
Response:
Return value: -1073741515
i.e. there is no output but the error code 1073741515 is displayed
Expecting to get back rows of data from MySQL database.
UPDATE: 10/3/25
I checked again the error code and it should be -1073741515 (minus 1073741515). This converts to C0000135 Hex 2s complement.
Feedback responses:
-1073741515 as a file system error not MySQL error? If this is the case how do I identify which file is missing? Does it suggest that the issue is a file permissions error?
Apache runs as user: SYSTEM - The PC runs as a web server with Apache (not IIS) as the front end.
MySQL runs as a Network Service but can also run as a local user. The application runs with MySQL "root" access.
The PHP script runs as user SYSTEM
I am unable to get the c++ GetUserName function working - due to a lack of c++ programming experience and missing c++ dll's on my PC. ie my environment is set up for c programming not c++.
Response to possible duplicates: What does Error-code 0xc0000135 (or -1073741515 Exit-code) mean when starting a Windows
.NET Framework 3.5 is installed. Activating it starts IIS and locks out Apache. Currently it is switched off. If the issue is .NET -- I can still run a "Hello World" c program from PHP but cannot run a database query written in c as an exe and both programs work when run from the command line. i.e. .NET does not seem to be the issue. My anti-virus does not block the "Hello World" problem so I have discounted this as the problem. There are no .NET errors displayed when running the app.
I also turned on/off my anti-virus. This made no difference.
I have checked the Event logs and can find nothing related to this issue.
When running the app there is no message: "The application failed to initialize properly (0xc0000135)".
Share Improve this question asked Mar 11 at 9:13 MichaelDMichaelD 311 silver badge5 bronze badges 4- What dependencies does your libmysql.dll has? – Pavel P Commented Mar 11 at 9:23
- You rote "Modifying the code to do a simple "Hello World" is successful." - does that mean you have successfully executed that hello world exe via PHP? – Robert Commented Mar 11 at 12:56
- I have successfully run the "Hello World" program from PHP. It is only when the my other c program trys to access the MYSQL database it fails with no output except the error code. – MichaelD Commented Mar 13 at 17:36
- Do I need to install and use Dependency Walker to determine what dependencies libmysql.dll has or is there another way? libmysql.dll was copied to windows/system32 to see if this would solve the problem. I have removed it from /system32 – MichaelD Commented Mar 13 at 17:39
2 Answers
Reset to default 1You cannot simply copy libmysql.dll to your windows/system32. It depends on some other dlls (perhaps, even some runtime libs from msys2) and, as a result, you get 0xc0000135 when you try to run your app.
As everything I tried provided no diagnostic information about the problem I went back to basics.
I assumed that Apache was the problem and did not have the correct permissions to access MySQL - even though it could run a .exe program. It has permission under the Local Systems account on my PC to access and run an .exe such as my c coded "Hello World" program which it did successfully.
So I gave Apache Administrators rights in:
Services->select Apache->select Log On->select 'This account-> and provide the Administrator username and password. Click Apply and stop and restart Apache.
And it worked. I can now access the MySQL data.
Thank you all for your help and suggestions.
Finally does anyone have any advice/concerns about giving Apache Administrator rights?