The following basic code is working as expected.
<?php
mysql_connect("localhost", "user", "user@123") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
What all I need is that instead of mysql_error, page not found 404 error should be returned.
I am looking for the shortest possible code since this is going to be used as load balancer check.
The following does not seem to work. I get a blank page.
mysql_connect("localhost", "user", "user@123") or die(header("HTTP/1.0 404 Not Found"));
I would do the following: bearing in mind I am using mysqli instead, the use of mysql_* is highly discouraged.
Are you sure you want to return a 404 though, this is misleading as the resource has been found, I would be returning a 500 error as a server error which would be more appropriate.
For a list of HTTP status codes see here